Module: Maestrano::Connector::Rails::Concerns::SubEntityBase
- Extended by:
- ActiveSupport::Concern
- Included in:
- SubEntityBase
- Defined in:
- app/models/maestrano/connector/rails/concerns/sub_entity_base.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #map_external_entity_with_idmap(external_entity, connec_entity_name, idmap, organization) ⇒ Object
- #map_to(name, entity, organization) ⇒ Object
Instance Method Details
#map_external_entity_with_idmap(external_entity, connec_entity_name, idmap, organization) ⇒ Object
102 103 104 |
# File 'app/models/maestrano/connector/rails/concerns/sub_entity_base.rb', line 102 def map_external_entity_with_idmap(external_entity, connec_entity_name, idmap, organization) {entity: map_to(connec_entity_name, external_entity, organization), idmap: idmap} end |
#map_to(name, entity, organization) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/models/maestrano/connector/rails/concerns/sub_entity_base.rb', line 81 def map_to(name, entity, organization) mapper = self.class.mapper_classes[name] raise "Impossible mapping from #{self.class.entity_name} to #{name}" unless mapper ref_hash = {} if self.class.references[name] self.class.references[name].each do |ref| field = self.class.external? ? ref[:connec_field] : ref[:external_field] ref_hash.merge! field.split('/').reverse.inject(Maestrano::Connector::Rails::Entity.id_from_ref(entity, ref, self.class.external?, organization)) { |a, n| { n.to_sym => a } } end end if self.class.external? mapped_entity = mapper.denormalize(entity) else mapped_entity = mapper.normalize(entity) end mapped_entity.merge(ref_hash) end |