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_and_complete_hash_with_connec_ids(external_hash, external_entity_name, connec_hash) ⇒ Object
Maps the entity received from external after a creation or an update and complete the received ids with the connec ones.
- #map_to(name, entity, idmap = nil) ⇒ Object
Instance Method Details
#map_and_complete_hash_with_connec_ids(external_hash, external_entity_name, connec_hash) ⇒ Object
Maps the entity received from external after a creation or an update and complete the received ids with the connec ones
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/maestrano/connector/rails/concerns/sub_entity_base.rb', line 67 def map_and_complete_hash_with_connec_ids(external_hash, external_entity_name, connec_hash) return nil if connec_hash.empty? # As we don't know to which complex entity this sub entity is related to, we have to do a full scan of the entities to find the right one # Because we need the external_entities_names external_entity_instance = Maestrano::Connector::Rails::ComplexEntity.find_complex_entity_and_instantiate_external_sub_entity_instance(external_entity_name, @organization, @connec_client, @external_client, @opts) return nil unless external_entity_instance mapped_external_hash = external_entity_instance.map_to(self.class.connec_entity_name, external_hash) id_references = Maestrano::Connector::Rails::ConnecHelper.format_references(self.class.references[external_entity_name]) Maestrano::Connector::Rails::ConnecHelper.merge_id_hashes(connec_hash, mapped_external_hash, id_references[:id_references]) end |
#map_to(name, entity, idmap = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/models/maestrano/connector/rails/concerns/sub_entity_base.rb', line 54 def map_to(name, entity, idmap = nil) first_time_mapped = self.class.external? ? idmap&.last_push_to_connec.nil? : idmap&.last_push_to_external.nil? mapper = first_time_mapped ? self.class.creation_mapper_classes[name] : self.class.mapper_classes[name] raise "Impossible mapping from #{self.class.entity_name} to #{name}" unless mapper if self.class.external? map_to_connec_helper(entity, mapper, self.class.references[name] || []) else map_to_external_helper(entity.merge(idmap: idmap), mapper) end end |