Module: MassiveRecord::ORM::Persistence::Operations::Embedded::OperationHelpers
- Defined in:
- lib/massive_record/orm/persistence/operations/embedded/operation_helpers.rb
Instance Method Summary collapse
- #embedded_in_proxies ⇒ Object
- #embedded_in_proxy_targets ⇒ Object
- #inverse_proxy_for(proxy) ⇒ Object
- #raise_error_if_embedded_in_proxy_targets_are_missing ⇒ Object
- #row_for_record(record) ⇒ Object
- #update_embedded(relation_proxy, value) ⇒ Object
Instance Method Details
#embedded_in_proxies ⇒ Object
7 8 9 |
# File 'lib/massive_record/orm/persistence/operations/embedded/operation_helpers.rb', line 7 def record.relation_proxies.select { |proxy| proxy.. } end |
#embedded_in_proxy_targets ⇒ Object
11 12 13 |
# File 'lib/massive_record/orm/persistence/operations/embedded/operation_helpers.rb', line 11 def .collect(&:load_proxy_target).compact end |
#inverse_proxy_for(proxy) ⇒ Object
47 48 49 |
# File 'lib/massive_record/orm/persistence/operations/embedded/operation_helpers.rb', line 47 def inverse_proxy_for(proxy) proxy.load_proxy_target.send(:relation_proxy, proxy..inverse_of) end |
#raise_error_if_embedded_in_proxy_targets_are_missing ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/massive_record/orm/persistence/operations/embedded/operation_helpers.rb', line 15 def relations_not_assigned = [] relations_assigned = [] .each do |proxy| if proxy.load_proxy_target.nil? relations_not_assigned << proxy..name else relations_assigned << proxy..name end end if relations_assigned.empty? raise MassiveRecord::ORM::NotAssignedToEmbeddedCollection.new(record, relations_not_assigned) end end |
#row_for_record(record) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/massive_record/orm/persistence/operations/embedded/operation_helpers.rb', line 52 def row_for_record(record) raise IdMissing.new("You must set an ID before save.") if record.id.blank? MassiveRecord::Wrapper::Row.new({ :id => record.id, :table => record.class.table }) end |
#update_embedded(relation_proxy, value) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/massive_record/orm/persistence/operations/embedded/operation_helpers.rb', line 32 def (relation_proxy, value) row = row_for_record(relation_proxy) row.values = { inverse_proxy_for(relation_proxy)..store_in => { record.database_id => value } } row.save end |