Module: MassiveRecord::ORM::Schema::ColumnInterface::ClassMethods
- Defined in:
- lib/massive_record/orm/schema/column_interface.rb
Instance Method Summary collapse
-
#add_field(*args) ⇒ Object
If you need to add fields dynamically, use this method.
-
#field(*args) ⇒ Object
DSL method exposed into class.
- #timestamps ⇒ Object
Instance Method Details
#add_field(*args) ⇒ Object
If you need to add fields dynamically, use this method. It wraps functionality needed to keep the class in a consistent state. There is also an instance method defined which will inject default value to the object itself after defining the field.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/massive_record/orm/schema/column_interface.rb', line 43 def add_field(*args) ensure_fields_exists field = Field.new_with_arguments_from_dsl(*args) fields << field undefine_attribute_methods if respond_to? :undefine_attribute_methods field end |
#field(*args) ⇒ Object
DSL method exposed into class. Makes it possible to do:
class Person < MassiveRecord::ORM::Column
field :name
field :age, :integer, :default => 0
field :points, :integer, :column => :number_of_points
end
27 28 29 30 |
# File 'lib/massive_record/orm/schema/column_interface.rb', line 27 def field(*args) ensure_fields_exists fields << Field.new_with_arguments_from_dsl(*args) end |
#timestamps ⇒ Object
33 34 35 |
# File 'lib/massive_record/orm/schema/column_interface.rb', line 33 def add_field :created_at, :time end |