Class: Eco::API::Common::People::PersonFactory
- Inherits:
-
Object
- Object
- Eco::API::Common::People::PersonFactory
- 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
-
#schema ⇒ Ecoportal::API::V1::PersonSchema
readonly
person schema to be used in this person factory.
-
#schema_attrs ⇒ Array<String>
readonly
inernal names of the schema fields/attributes.
Instance Method Summary collapse
-
#initialize(person: nil, schema: {}, account: {}, modifier: Common::People::PersonModifier.new) ⇒ PersonFactory
constructor
A new instance of PersonFactory.
- #new(person: nil) ⇒ Object
- #new_contact(schema) ⇒ Object
- #new_doc ⇒ Object
- #schema_id ⇒ Object
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 = account @schema = schema @schema_attrs = @schema&.fields&.map { |fld| fld.alt_id } end |
Instance Attribute Details
#schema ⇒ Ecoportal::API::V1::PersonSchema (readonly)
person schema to be used in this person factory
9 10 11 |
# File 'lib/eco/api/common/people/person_factory.rb', line 9 def schema @schema end |
#schema_attrs ⇒ Array<String> (readonly)
inernal names of the schema fields/attributes
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 = account_hash(@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.reset_account, person: @person, schema: @schema, account: @account) factory.new end |
#new_doc ⇒ Object
35 36 37 |
# File 'lib/eco/api/common/people/person_factory.rb', line 35 def new_doc new_hash(@modifier) end |
#schema_id ⇒ Object
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 |