Class: 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 = @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.
11 12 13 14 15 16 17 |
# File 'lib/eco/api/common/people/person_factory.rb', line 11 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(&:alt_id) end |
Instance Attribute Details
#schema ⇒ Ecoportal::API::V1::PersonSchema (readonly)
person schema to be used in this person factory
8 9 10 |
# File 'lib/eco/api/common/people/person_factory.rb', line 8 def schema @schema end |
#schema_attrs ⇒ Array<String> (readonly)
inernal names of the schema fields/attributes
8 9 10 |
# File 'lib/eco/api/common/people/person_factory.rb', line 8 def schema_attrs @schema_attrs end |
Instance Method Details
#new(person: nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/eco/api/common/people/person_factory.rb', line 19 def new(person: nil) in_raw_modifier = Common::People::PersonModifier.new.no_details if person return PersonFactory.new( person: person, schema: @schema, modifier: in_raw_modifier ).new end 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 = @schema) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/eco/api/common/people/person_factory.rb', line 36 def new_contact(schema = @schema) factory = self.class.new( @modifier.reset_account, person: @person, schema: schema, account: @account ) factory.new end |
#new_doc ⇒ Object
46 47 48 |
# File 'lib/eco/api/common/people/person_factory.rb', line 46 def new_doc new_hash(@modifier) end |
#schema_id ⇒ Object
50 51 52 53 |
# File 'lib/eco/api/common/people/person_factory.rb', line 50 def schema_id nil unless @schema @schema['schema_id'] || @schema['id'] end |