Module: PassiveRecord::Schema::ClassMethods

Defined in:
lib/passive_record/schema.rb

Instance Method Summary collapse

Instance Method Details

#schema(definition = {}) ⇒ Object

Define the schema for your model, this also adds attribute accessors for schema columns



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/passive_record/schema.rb', line 11

def schema(definition = {})
  @@schema = definition
  definition.keys.each do |attribute_name|
    define_method("#{attribute_name}") do
      self[attribute_name]
    end
    define_method("#{attribute_name}=") do |new_value|
      self[attribute_name] = new_value
    end
  end
end