Class: Ecoportal::API::Internal::Person
- Inherits:
-
V1::Person
- Object
- Common::BaseModel
- V1::Person
- Ecoportal::API::Internal::Person
- Defined in:
- lib/ecoportal/api/internal/person.rb
Constant Summary
Constants inherited from V1::Person
V1::Person::NON_PHONE_REGEX, V1::Person::VALID_EMAIL_REGEX, V1::Person::VALID_TAG_REGEX
Instance Attribute Summary collapse
-
#account ⇒ Account?
the account of the person or
nilif missing.
Attributes inherited from V1::Person
#contractor_organization_id, #details, #external_id, #id, #name, #supervisor_id
Attributes inherited from Common::BaseModel
Instance Method Summary collapse
-
#account_added?(value = :original) ⇒ Boolean
If the account has been added to
doc. -
#account_removed?(value = :original) ⇒ Boolean
If the account has been removed from
doc. -
#add_account ⇒ Object
Adds an empty account to the person.
- #as_json ⇒ Object
- #as_update(ref = :last, ignore: []) ⇒ Object
- #consolidate! ⇒ Object
-
#initialize(doc = {}, *args, **kargs, &block) ⇒ Person
constructor
A new instance of Person.
-
#new?(value = :original) ⇒ Boolean
Whether or not this entry is being created now (i.e. non existent on server).
- #reset!(*args) ⇒ Object
Methods inherited from V1::Person
#add_details, #archive!, #email=, #filter_tags, #filter_tags=, #phone_number=, #supervisor, #supervisor=, #unarchive!
Methods inherited from Common::BaseModel
#dirty?, #doc, embeds_one, #initial_doc, #original_doc, passthrough, #print_pretty, #replace_doc!, #replace_original_doc!, #to_json
Methods included from Common::BaseClass
#class_resolver, #redef_without_warning, #resolve_class
Constructor Details
#initialize(doc = {}, *args, **kargs, &block) ⇒ Person
Returns a new instance of Person.
10 11 12 13 14 |
# File 'lib/ecoportal/api/internal/person.rb', line 10 def initialize(doc = {}, *args, **kargs, &block) super @is_new = @prev_is_new = no_account_nor_details?(@doc) end |
Instance Attribute Details
#account ⇒ Account?
the account of the person or nil if missing.
5 6 7 |
# File 'lib/ecoportal/api/internal/person.rb', line 5 def account @account end |
Instance Method Details
#account_added?(value = :original) ⇒ Boolean
Returns if the account has been added to doc.
45 46 47 48 |
# File 'lib/ecoportal/api/internal/person.rb', line 45 def account_added?(value = :original) ref_doc = value == :original ? original_doc : initial_doc !!account && !ref_doc['account'] end |
#account_removed?(value = :original) ⇒ Boolean
Returns if the account has been removed from doc.
51 52 53 54 |
# File 'lib/ecoportal/api/internal/person.rb', line 51 def account_removed?(value = :original) ref_doc = value == :original ? original_doc : initial_doc !account && !!ref_doc['account'] end |
#add_account ⇒ Object
if the person exists, and does not have an account, an this will send an invite.
this will not change the account properties of this person.
Adds an empty account to the person.
93 94 95 |
# File 'lib/ecoportal/api/internal/person.rb', line 93 def add_account self.account = {} end |
#as_json ⇒ Object
56 57 58 |
# File 'lib/ecoportal/api/internal/person.rb', line 56 def as_json super.update('account' => account&.as_json) end |
#as_update(ref = :last, ignore: []) ⇒ Object
60 61 62 |
# File 'lib/ecoportal/api/internal/person.rb', line 60 def as_update(ref = :last, ignore: []) super(ref, ignore: ignore | %w[user_id permissions_merged prefilter]) end |
#consolidate! ⇒ Object
16 17 18 19 20 21 |
# File 'lib/ecoportal/api/internal/person.rb', line 16 def consolidate! @prev_is_new = @is_new @is_new = false super end |
#new?(value = :original) ⇒ Boolean
original_docshould technically hold the model as it is on server side- Once this person has been successfullyupdated,
#consolidate!should be called. - The above sets a copy of
docasoriginal_doc(meaning: no pending changes) - Therefore we can safely assume that this is a new record if the
original_docdoes not have details nor account (as all people should have either to exist). - However, to the purpose of getting a clean
as_update,original_docis filled withdetailsright on creation. For this reason, a workaround is necessary via@is_new
Returns whether or not this entry is being created now (i.e. non existent on server).
38 39 40 41 42 |
# File 'lib/ecoportal/api/internal/person.rb', line 38 def new?(value = :original) return @is_new if value == :original no_account_nor_details?(initial_doc) end |
#reset!(*args) ⇒ Object
23 24 25 26 27 |
# File 'lib/ecoportal/api/internal/person.rb', line 23 def reset!(*args) @is_new = @prev_is_new super end |