Module: Maestrano::Connector::Rails::Concerns::Entity::ClassMethods

Defined in:
app/models/maestrano/connector/rails/concerns/entity.rb

Instance Method Summary collapse

Instance Method Details

#can_read_connec?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 114

def can_read_connec?
  can_write_external?
end

#can_read_external?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 118

def can_read_external?
  can_write_connec?
end

#can_update_connec?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 122

def can_update_connec?
  true
end

#can_update_external?Boolean

Returns:

  • (Boolean)


134
135
136
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 134

def can_update_external?
  true
end

#can_write_connec?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 126

def can_write_connec?
  true
end

#can_write_external?Boolean

Returns:

  • (Boolean)


130
131
132
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 130

def can_write_external?
  true
end

#connec_entity_nameObject

Entity name in Connec!



84
85
86
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 84

def connec_entity_name
  raise 'Not implemented'
end

#connec_matching_fieldsObject

An array of fields for smart merging. See Connec! documentation



110
111
112
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 110

def connec_matching_fields
  nil
end

#count_and_first(entities) ⇒ Object


Helper methods

Returns the count and first element of the array Used for batch calling during the first synchronization



147
148
149
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 147

def count_and_first(entities)
  {count: entities.size, first: entities.first}
end

#create_idmap(organization_and_id) ⇒ Object



28
29
30
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 28

def create_idmap(organization_and_id)
  Maestrano::Connector::Rails::IdMap.create(names_hash.merge(organization_and_id))
end

#creation_date_from_external_entity_hash(entity) ⇒ Object



54
55
56
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 54

def creation_date_from_external_entity_hash(entity)
  raise 'Not implemented'
end

#creation_mapper_classObject

Optional creation only mapper, defaults to main mapper



99
100
101
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 99

def creation_mapper_class
  mapper_class
end

#currency_check_fieldsObject



138
139
140
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 138

def currency_check_fields
  nil
end

#external_entity_nameObject

Entity name in external system



89
90
91
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 89

def external_entity_name
  raise 'Not implemented'
end

#find_idmap(organization_and_id) ⇒ Object



24
25
26
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 24

def find_idmap(organization_and_id)
  Maestrano::Connector::Rails::IdMap.find_by(names_hash.merge(organization_and_id))
end

#find_or_create_idmap(organization_and_id) ⇒ Object

organization_and_id can be either:

  • ‘id’, organization_id: ‘id’

  • ‘id’, organization_id: ‘id’

Needs to include either connec_entity or external_entity for sub entities



20
21
22
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 20

def find_or_create_idmap(organization_and_id)
  Maestrano::Connector::Rails::IdMap.find_or_create_by(names_hash.merge(organization_and_id))
end

#id_from_external_entity_hash(entity) ⇒ Object


External methods



46
47
48
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 46

def id_from_external_entity_hash(entity)
  raise 'Not implemented'
end

#inactive_from_external_entity_hash?(entity) ⇒ Boolean

Returns a boolean Returns true is the entity is flagged as inactive (deleted) in the external application

Returns:

  • (Boolean)


70
71
72
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 70

def inactive_from_external_entity_hash?(entity)
  false
end

#last_update_date_from_external_entity_hash(entity) ⇒ Object



50
51
52
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 50

def last_update_date_from_external_entity_hash(entity)
  raise 'Not implemented'
end

#mapper_classObject

Entity Mapper Class



94
95
96
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 94

def mapper_class
  raise 'Not implemented'
end

#names_hashObject


IdMap methods

Default names hash used for id maps creation and look up



9
10
11
12
13
14
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 9

def names_hash
  {
    connec_entity: connec_entity_name.downcase,
    external_entity: external_entity_name.downcase
  }
end

#normalize_connec_entity_name(name) ⇒ Object



39
40
41
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 39

def normalize_connec_entity_name(name)
  singleton? ? name.parameterize('_') : name.parameterize('_').pluralize
end

#normalized_connec_entity_nameObject


Connec! methods



35
36
37
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 35

def normalized_connec_entity_name
  normalize_connec_entity_name(connec_entity_name)
end

#object_name_from_connec_entity_hash(entity) ⇒ Object

Return a string representing the object from a connec! entity hash



59
60
61
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 59

def object_name_from_connec_entity_hash(entity)
  raise 'Not implemented'
end

#object_name_from_external_entity_hash(entity) ⇒ Object

Return a string representing the object from an external entity hash



64
65
66
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 64

def object_name_from_external_entity_hash(entity)
  raise 'Not implemented'
end

#public_connec_entity_nameObject

For display purposes only



152
153
154
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 152

def public_connec_entity_name
  singleton? ? connec_entity_name : connec_entity_name.pluralize
end

#public_external_entity_nameObject

For display purposes only



157
158
159
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 157

def public_external_entity_name
  external_entity_name.pluralize
end

#referencesObject

An array of connec fields that are references Can also be an hash with keys record_references and id_references



105
106
107
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 105

def references
  []
end

#singleton?Boolean


Entity specific methods

Those methods need to be define in each entity


Is this resource a singleton (in Connec!)?

Returns:

  • (Boolean)


79
80
81
# File 'app/models/maestrano/connector/rails/concerns/entity.rb', line 79

def singleton?
  false
end