Module: MassiveRecord::ORM::Schema::TableInterface::ClassMethods
- Defined in:
- lib/massive_record/orm/schema/table_interface.rb
Instance Method Summary collapse
-
#add_column_family(name) ⇒ Object
Adds a column family to your class.
-
#add_field_to_column_family(family_name, *field_args) ⇒ Object
If you need to add fields to a column family dynamically, use this method.
-
#autoload_column_families_and_fields_with(column_names) ⇒ Object
Create column families and fields with incomming array of column names.
-
#column_family(name, &block) ⇒ Object
DSL method exposed into class.
-
#known_column_family_names ⇒ Object
Makes it a bit more convenient to get all the column family names.
Instance Method Details
#add_column_family(name) ⇒ Object
Adds a column family to your class
37 38 39 40 |
# File 'lib/massive_record/orm/schema/table_interface.rb', line 37 def add_column_family(name) ensure_column_families_exists column_families.family_by_name_or_new(name) end |
#add_field_to_column_family(family_name, *field_args) ⇒ Object
If you need to add fields to a column family 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.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/massive_record/orm/schema/table_interface.rb', line 48 def add_field_to_column_family(family_name, *field_args) ensure_column_families_exists field = Field.new_with_arguments_from_dsl(*field_args) column_families.family_by_name_or_new(family_name) << field undefine_attribute_methods if respond_to? :undefine_attribute_methods field end |
#autoload_column_families_and_fields_with(column_names) ⇒ Object
Create column families and fields with incomming array of column names. It should be on a unique and complete form like [“info:name”, “info:phone”]
63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/massive_record/orm/schema/table_interface.rb', line 63 def autoload_column_families_and_fields_with(column_names) ensure_column_families_exists column_names.each do |column_family_and_column_name| family_name, column_name = column_family_and_column_name.split(":") if family = column_families.family_by_name(family_name) and family.autoload_fields? family.add?(Field.new( family..merge(:name => column_name) )) end end end |
#column_family(name, &block) ⇒ Object
DSL method exposed into class. Makes it possible to do:
class Person < MassiveRecord::ORM::Table
column_family :info do
field :name
field :age, :integer, :default => 0
field :points, :integer, :column => :number_of_points
end
end
30 31 32 |
# File 'lib/massive_record/orm/schema/table_interface.rb', line 30 def column_family(name, &block) add_column_family(name).instance_eval(&block) end |
#known_column_family_names ⇒ Object
Makes it a bit more convenient to get all the column family names
80 81 82 |
# File 'lib/massive_record/orm/schema/table_interface.rb', line 80 def known_column_family_names (column_families || []).collect &:name end |