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.
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.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/massive_record/orm/schema/column_interface.rb', line 38 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 |