Module: MassiveRecord::ORM::Schema::EmbeddedInterface
- Extended by:
- ActiveSupport::Concern
- Included in:
- Embedded
- Defined in:
- lib/massive_record/orm/schema/embedded_interface.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#add_field(*args) ⇒ Object
Same as defined in class method, but also sets the default value in current object it was called from.
-
#attributes_db_raw_data_hash(only_attr_names = []) ⇒ Object
Returns attributes as a hash which has correct keys based on it’s field definition.
- #attributes_to_row_values_hash(only_attr_names = []) ⇒ Object
Instance Method Details
#add_field(*args) ⇒ Object
Same as defined in class method, but also sets the default value in current object it was called from.
100 101 102 103 104 |
# File 'lib/massive_record/orm/schema/embedded_interface.rb', line 100 def add_field(*args) new_field = self.class.add_field(*args) method = "#{new_field.name}=" send(method, new_field.default) if respond_to? method end |
#attributes_db_raw_data_hash(only_attr_names = []) ⇒ Object
Returns attributes as a hash which has correct keys based on it’s field definition. For instance, you can have a class with a field :attr_name, :column => :stored_as_this
112 113 114 115 116 117 118 119 120 121 |
# File 'lib/massive_record/orm/schema/embedded_interface.rb', line 112 def attributes_db_raw_data_hash(only_attr_names = []) values = Hash.new attributes_schema.each do |attr_name, orm_field| next unless only_attr_names.empty? || only_attr_names.include?(attr_name) values[orm_field.column] = orm_field.encode(send(attr_name)) end values end |
#attributes_to_row_values_hash(only_attr_names = []) ⇒ Object
123 124 125 126 |
# File 'lib/massive_record/orm/schema/embedded_interface.rb', line 123 def attributes_to_row_values_hash(only_attr_names = []) ActiveSupport::Deprecation.warn("attributes_to_row_values_hash is deprecated. Please use attributes_db_raw_data_hash") attributes_db_raw_data_hash(only_attr_names) end |