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::VALID_EMAIL_REGEX, V1::Person::VALID_TAG_REGEX
Instance Attribute Summary collapse
-
#account ⇒ Account?
the account of the person or
nil
if 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, #email=, #filter_tags, #filter_tags=, #supervisor, #supervisor=
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 |
# File 'lib/ecoportal/api/internal/person.rb', line 10 def initialize(doc = {}, *args, **kargs, &block) super(doc, *args, **kargs, &block) @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
.
41 42 43 44 |
# File 'lib/ecoportal/api/internal/person.rb', line 41 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
.
47 48 49 50 |
# File 'lib/ecoportal/api/internal/person.rb', line 47 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.
88 89 90 |
# File 'lib/ecoportal/api/internal/person.rb', line 88 def add_account self.account = {} end |
#as_json ⇒ Object
52 53 54 |
# File 'lib/ecoportal/api/internal/person.rb', line 52 def as_json super.update("account" => account&.as_json) end |
#as_update(ref = :last, ignore: []) ⇒ Object
56 57 58 |
# File 'lib/ecoportal/api/internal/person.rb', line 56 def as_update(ref = :last, ignore: []) super(ref, ignore: ignore | ["user_id", "permissions_merged", "prefilter"]) end |
#consolidate! ⇒ Object
15 16 17 18 19 |
# File 'lib/ecoportal/api/internal/person.rb', line 15 def consolidate! @prev_is_new = @is_new @is_new = false super end |
#new?(value = :original) ⇒ Boolean
original_doc
should 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
doc
asoriginal_doc
(meaning: no pending changes) - Therefore we can safely assume that this is a new record if the
original_doc
does not have details nor account (as all people should have either to exist). - However, to the purpose of getting a clean
as_update
,original_doc
is filled withdetails
right 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).
35 36 37 38 |
# File 'lib/ecoportal/api/internal/person.rb', line 35 def new?(value = :original) return @is_new if value == :original no_account_nor_details?(initial_doc) end |
#reset!(*args) ⇒ Object
21 22 23 24 |
# File 'lib/ecoportal/api/internal/person.rb', line 21 def reset!(*args) @is_new = @prev_is_new super(*args) end |