Class: Eco::API::Common::People::PersonFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/eco/api/common/people/person_factory.rb

Overview

Helper factory to build Ecoportal::API::V1::Person or Ecoportal::API::Internal::Person objects

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(person: nil, schema: {}, account: {}, modifier: Common::People::PersonModifier.new) ⇒ PersonFactory

Returns a new instance of PersonFactory.



13
14
15
16
17
18
19
# File 'lib/eco/api/common/people/person_factory.rb', line 13

def initialize(person: nil, schema: {}, account: {}, modifier: Common::People::PersonModifier.new)
  @modifier = Common::People::PersonModifier.new(modifier)
  @person  = person
  @account = 
  @schema  = schema
  @schema_attrs = @schema&.fields&.map { |fld| fld.alt_id }
end

Instance Attribute Details

#schemaEcoportal::API::V1::PersonSchema (readonly)

person schema to be used in this person factory

Returns:

  • (Ecoportal::API::V1::PersonSchema)

    the current value of schema



9
10
11
# File 'lib/eco/api/common/people/person_factory.rb', line 9

def schema
  @schema
end

#schema_attrsArray<String> (readonly)

inernal names of the schema fields/attributes

Returns:

  • (Array<String>)

    the current value of schema_attrs



9
10
11
# File 'lib/eco/api/common/people/person_factory.rb', line 9

def schema_attrs
  @schema_attrs
end

Instance Method Details

#new(person: nil) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/eco/api/common/people/person_factory.rb', line 21

def new(person: nil)
  in_raw_modifier = Common::People::PersonModifier.new.no_details
  return PersonFactory.new(person: person, schema: @schema, modifier: in_raw_modifier).new unless !person
  person = klass.new(person_hash(@person))
  person. = (@account) if @modifier.add_account? && @modifier.internal?
  person.add_details(@schema) unless @modifier.no_details?
  person
end

#new_contact(schema) ⇒ Object



30
31
32
33
# File 'lib/eco/api/common/people/person_factory.rb', line 30

def new_contact(schema)
  factory = self.class.new(@modifier., person: @person, schema: @schema, account: @account)
  factory.new
end

#new_docObject



35
36
37
# File 'lib/eco/api/common/people/person_factory.rb', line 35

def new_doc
  new_hash(@modifier)
end

#schema_idObject



39
40
41
42
# File 'lib/eco/api/common/people/person_factory.rb', line 39

def schema_id
  nil if !@schema
  @schema['schema_id'] || @schema['id']
end