https://github.com/taskrabbit/meta_content
https://github.com/taskrabbit/meta_content
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/taskrabbit/meta_content
- Owner: taskrabbit
- License: mit
- Created: 2013-03-28T05:29:55.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2013-06-25T20:30:25.000Z (over 12 years ago)
- Last Synced: 2025-01-02T11:27:18.049Z (about 1 year ago)
- Language: Ruby
- Size: 195 KB
- Stars: 0
- Watchers: 41
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MetaContent
Store document values in MySQL in a separate key/value table.
I'm sure this exists already, but we couldn't find one.
## Installation
Add this line to your application's Gemfile:
gem 'meta_content'
And then execute:
$ bundle
Or install it yourself as:
$ gem install meta_content
## Migration
```ruby
class CreateTaskMeta < ActiveRecord::Migration
def up
create_table :tasks_meta do |t|
t.integer :object_id, :null => false
t.string :namespace, :null => false
t.string :lookup, :null => false
t.string :value
t.integer :int_value
end
add_index :tasks_meta, [:object_id, :namespace, :lookup], unique: true
add_index :tasks_meta, :object_id
end
def down
drop_table :tasks_meta
end
end
```
## Model
```ruby
class Task < ActiveRecord::Base
meta do
string :name
integer :price
float :hours, :default => 1.0
end
meta :timing do
datetime :start_at
string :description
boolean :flexible, :default => false
end
end
```
## Usage
This gives getters and setters for everything defined:
```ruby
task = Task.new
task.name = "Store meta info"
task.price = 20
task.hours = 3.2
task.timing_start_at = 3.hours.from_now
task.timing_description = "Tonight or otherwise by Friday"
task.timing_flexible = true
task.save!
```
Everything gets saved in the `tasks_meta` table. Updating and saving updates those rows.
overall, it works like they were regular columns.