Module: Models::PartyIdentity
- Extended by:
- ActiveSupport::Concern
- Included in:
- Party
- Defined in:
- app/concerns/models/party_identity.rb
Overview
Name fields, display helpers, and type/role predicates for Party STI records.
== person? / organization? / homeowner? predicate resolution
The bare predicates defined here are the Party defaults. Customer and Contact
override them with subtly different semantics; pay attention when calling
them on a base Party versus the subclass:
- On Customer (Models::CustomerOrganization):
person?==homeowner?
organization?==!homeowner? - On Contact:
person?always true
organization?==!homeowner?(delegated to its customer) - Note:
is_homeowner?/is_organization?defined on Contact delegate to the
contact's customer, while barehomeowner?/organization?use the
Models::PartyIdentity definitions on the contact itself.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Whether this party is currently active.
-
#admin? ⇒ Boolean
Whether this party has admin privileges.
-
#aka ⇒ String
"Also known as" nickname stored in
name2when the party is not a person. -
#aka=(name) ⇒ String?
Sets the nickname, but only for non-person parties.
-
#all_activities ⇒ ActiveRecord::Associations::CollectionProxy<Activity>
Activities linked to this party.
-
#blog_admin? ⇒ Boolean
Whether this party has blog admin privileges.
-
#broadcast_product_interest_changed(product_line_ids_added: [], product_line_ids_removed: []) ⇒ void
Broadcasts a product-interest change for this party.
-
#can_be_certified? ⇒ Boolean
Whether this party type supports certification.
-
#can_list_all_contact_resources? ⇒ Boolean
Whether this party can list all contact resources.
-
#clear_individual_names ⇒ nil
Clears the individual first/middle/last name fields.
-
#clear_names ⇒ nil
Clears all name fields and the full name.
-
#contact? ⇒ Boolean
(also: #is_contact?)
Whether this record is a Contact.
-
#customer? ⇒ Boolean
(also: #is_customer?)
Whether this record is a Customer.
-
#determine_company_id ⇒ Integer
Resolves the company ID for this party.
-
#direct_commercial? ⇒ Boolean
(also: #is_direct_commercial?)
Whether this party is a direct commercial customer.
-
#direct_pro? ⇒ Boolean
(also: #is_direct_pro?)
Whether this party is a direct professional customer.
-
#employee? ⇒ Boolean
(also: #is_employee?)
Whether this record is an Employee.
-
#first_name ⇒ String
First/given name stored in
name1. -
#first_name=(name) ⇒ String?
Sets the first name, stripping whitespace and storing nil for blank values.
-
#guest_individual_name? ⇒ Boolean
(also: #has_guest_individual_name?)
Whether the first name is a guest placeholder.
-
#guest_name? ⇒ Boolean
(also: #has_guest_name?)
Whether the full name is a guest placeholder.
-
#homeowner? ⇒ Boolean
(also: #is_homeowner?)
Whether this party is a homeowner.
-
#id_and_name ⇒ String
Display string combining ID and full name.
-
#last_name ⇒ String
Last/family name stored in
name3. -
#last_name=(name) ⇒ String?
Sets the last name, stripping whitespace and storing nil for blank values.
-
#manager? ⇒ Boolean
Whether this party has manager privileges.
-
#middle_name ⇒ String
Middle name stored in
name2. -
#middle_name=(name) ⇒ String?
Sets the middle name, stripping whitespace and storing nil for blank values.
-
#name ⇒ String
Full display name, falling back to an empty string.
-
#name=(name_to_use) ⇒ String?
Parses and assigns a full name, splitting person names into components.
-
#organization? ⇒ Boolean
(also: #is_organization?)
Whether this party represents an organization.
-
#person? ⇒ Boolean
(also: #is_person?)
Whether this party represents an individual person.
-
#primary_party ⇒ Party
Returns this party as the primary party.
-
#public_facing_full_name ⇒ String?
Full name as it should appear in public-facing contexts.
-
#public_facing_full_name=(name) ⇒ String?
Assigns or clears the public-facing full name.
-
#show_name_four ⇒ String
(also: #show_name_4)
Compact four-character identifier used for some displays.
-
#to_s ⇒ String?
String representation of the party.
-
#update_product_interests(product_line_ids) ⇒ Array<Integer>
Replaces this party's product-line interests and broadcasts the change.
Instance Method Details
#active? ⇒ Boolean
Whether this party is currently active.
259 260 261 |
# File 'app/concerns/models/party_identity.rb', line 259 def active? !inactive? end |
#admin? ⇒ Boolean
Whether this party has admin privileges.
245 246 247 |
# File 'app/concerns/models/party_identity.rb', line 245 def admin? account&.has_role?('admin') end |
#aka ⇒ String
"Also known as" nickname stored in name2 when the party is not a person.
73 74 75 |
# File 'app/concerns/models/party_identity.rb', line 73 def aka name2 || '' end |
#aka=(name) ⇒ String?
Sets the nickname, but only for non-person parties.
81 82 83 |
# File 'app/concerns/models/party_identity.rb', line 81 def aka=(name) self.name2 = name unless person? end |
#all_activities ⇒ ActiveRecord::Associations::CollectionProxy<Activity>
Activities linked to this party.
319 320 321 |
# File 'app/concerns/models/party_identity.rb', line 319 def all_activities linked_activities end |
#blog_admin? ⇒ Boolean
Whether this party has blog admin privileges.
266 267 268 |
# File 'app/concerns/models/party_identity.rb', line 266 def blog_admin? account&.has_role?('blog_admin') end |
#broadcast_product_interest_changed(product_line_ids_added: [], product_line_ids_removed: []) ⇒ void
This method returns an undefined value.
Broadcasts a product-interest change for this party.
354 355 356 357 |
# File 'app/concerns/models/party_identity.rb', line 354 def broadcast_product_interest_changed(product_line_ids_added: [], product_line_ids_removed: []) PartyProductInterestSync.broadcast(self, added: product_line_ids_added, removed: product_line_ids_removed) end |
#can_be_certified? ⇒ Boolean
Whether this party type supports certification.
193 194 195 |
# File 'app/concerns/models/party_identity.rb', line 193 def can_be_certified? is_a?(Customer) || is_a?(Contact) || is_a?(Employee) end |
#can_list_all_contact_resources? ⇒ Boolean
Whether this party can list all contact resources.
273 274 275 276 277 278 279 280 281 282 283 |
# File 'app/concerns/models/party_identity.rb', line 273 def can_list_all_contact_resources? if instance_of?(::Customer) || (instance_of?(::Contact) && account && (account.is_online_customer_administrator? || account.is_online_customer_sales_supervisor? || account.is_online_customer_accounting_supervisor?)) true else instance_of?(::Employee) end end |
#clear_individual_names ⇒ nil
Clears the individual first/middle/last name fields.
121 122 123 124 125 |
# File 'app/concerns/models/party_identity.rb', line 121 def clear_individual_names self.name1 = nil self.name2 = nil self.name3 = nil end |
#clear_names ⇒ nil
Clears all name fields and the full name.
111 112 113 114 115 116 |
# File 'app/concerns/models/party_identity.rb', line 111 def clear_names self.name1 = nil self.name2 = nil self.name3 = nil self.full_name = nil end |
#contact? ⇒ Boolean Also known as: is_contact?
Whether this record is a Contact.
209 210 211 |
# File 'app/concerns/models/party_identity.rb', line 209 def contact? instance_of? Contact end |
#customer? ⇒ Boolean Also known as: is_customer?
Whether this record is a Customer.
200 201 202 |
# File 'app/concerns/models/party_identity.rb', line 200 def customer? instance_of? Customer end |
#determine_company_id ⇒ Integer
Resolves the company ID for this party.
295 296 297 298 299 300 |
# File 'app/concerns/models/party_identity.rb', line 295 def determine_company_id resolved = customer&.determine_company_id if respond_to?(:customer) resolved ||= self[:company_id] resolved ||= Company::USA resolved end |
#direct_commercial? ⇒ Boolean Also known as: is_direct_commercial?
Whether this party is a direct commercial customer.
184 185 186 |
# File 'app/concerns/models/party_identity.rb', line 184 def direct_commercial? customer&.profile&.direct_commercial? end |
#direct_pro? ⇒ Boolean Also known as: is_direct_pro?
Whether this party is a direct professional customer.
175 176 177 |
# File 'app/concerns/models/party_identity.rb', line 175 def direct_pro? customer&.profile&.direct_pro? end |
#employee? ⇒ Boolean Also known as: is_employee?
Whether this record is an Employee.
218 219 220 |
# File 'app/concerns/models/party_identity.rb', line 218 def employee? instance_of? Employee end |
#first_name ⇒ String
First/given name stored in name1.
28 29 30 |
# File 'app/concerns/models/party_identity.rb', line 28 def first_name name1 || '' end |
#first_name=(name) ⇒ String?
Sets the first name, stripping whitespace and storing nil for blank values.
36 37 38 |
# File 'app/concerns/models/party_identity.rb', line 36 def first_name=(name) self.name1 = name.presence&.strip end |
#guest_individual_name? ⇒ Boolean Also known as: has_guest_individual_name?
Whether the first name is a guest placeholder.
335 336 337 |
# File 'app/concerns/models/party_identity.rb', line 335 def guest_individual_name? name1 =~ /^Guest / || name1 == 'Guest' end |
#guest_name? ⇒ Boolean Also known as: has_guest_name?
Whether the full name is a guest placeholder.
326 327 328 |
# File 'app/concerns/models/party_identity.rb', line 326 def guest_name? full_name =~ /^Guest / || full_name == 'Guest' end |
#homeowner? ⇒ Boolean Also known as: is_homeowner?
Whether this party is a homeowner.
166 167 168 |
# File 'app/concerns/models/party_identity.rb', line 166 def homeowner? customer&.profile_id == ProfileConstants::HOMEOWNER end |
#id_and_name ⇒ String
Display string combining ID and full name.
305 306 307 |
# File 'app/concerns/models/party_identity.rb', line 305 def id_and_name "#{id} #{full_name}" end |
#last_name ⇒ String
Last/family name stored in name3.
58 59 60 |
# File 'app/concerns/models/party_identity.rb', line 58 def last_name name3 || '' end |
#last_name=(name) ⇒ String?
Sets the last name, stripping whitespace and storing nil for blank values.
66 67 68 |
# File 'app/concerns/models/party_identity.rb', line 66 def last_name=(name) self.name3 = name.presence&.strip end |
#manager? ⇒ Boolean
Whether this party has manager privileges.
252 253 254 |
# File 'app/concerns/models/party_identity.rb', line 252 def manager? account&.is_manager? end |
#middle_name ⇒ String
Middle name stored in name2.
43 44 45 |
# File 'app/concerns/models/party_identity.rb', line 43 def middle_name name2 || '' end |
#middle_name=(name) ⇒ String?
Sets the middle name, stripping whitespace and storing nil for blank values.
51 52 53 |
# File 'app/concerns/models/party_identity.rb', line 51 def middle_name=(name) self.name2 = name.presence&.strip end |
#name ⇒ String
Full display name, falling back to an empty string.
88 89 90 |
# File 'app/concerns/models/party_identity.rb', line 88 def name full_name || '' end |
#name=(name_to_use) ⇒ String?
Parses and assigns a full name, splitting person names into components.
96 97 98 99 100 101 102 103 104 105 106 |
# File 'app/concerns/models/party_identity.rb', line 96 def name=(name_to_use) logger.debug "Party#name called with #{name_to_use}" return if name_to_use.nil? || name_to_use.strip.empty? name_to_use&.strip! self.full_name = name_to_use return unless person? pnp = PersonNameParser.new name_to_use pnp.to_party(self) end |
#organization? ⇒ Boolean Also known as: is_organization?
Whether this party represents an organization.
236 237 238 |
# File 'app/concerns/models/party_identity.rb', line 236 def organization? !(homeowner? || employee?) end |
#person? ⇒ Boolean Also known as: is_person?
Whether this party represents an individual person.
227 228 229 |
# File 'app/concerns/models/party_identity.rb', line 227 def person? contact? || employee? # not all parties have homeowner? defined end |
#primary_party ⇒ Party
Returns this party as the primary party.
288 289 290 |
# File 'app/concerns/models/party_identity.rb', line 288 def primary_party self end |
#public_facing_full_name ⇒ String?
Full name as it should appear in public-facing contexts.
145 146 147 148 149 |
# File 'app/concerns/models/party_identity.rb', line 145 def public_facing_full_name return nil if guest_individual_name? full_name end |
#public_facing_full_name=(name) ⇒ String?
Assigns or clears the public-facing full name.
155 156 157 158 159 160 161 |
# File 'app/concerns/models/party_identity.rb', line 155 def public_facing_full_name=(name) if name.present? self.name = name else clear_individual_names end end |
#show_name_four ⇒ String Also known as: show_name_4
Compact four-character identifier used for some displays.
130 131 132 133 134 |
# File 'app/concerns/models/party_identity.rb', line 130 def show_name_four "#{first_name&.[](0)}#{last_name&.first(3)}".upcase rescue StandardError '' end |
#to_s ⇒ String?
String representation of the party.
312 313 314 |
# File 'app/concerns/models/party_identity.rb', line 312 def to_s full_name end |
#update_product_interests(product_line_ids) ⇒ Array<Integer>
Replaces this party's product-line interests and broadcasts the change.
345 346 347 |
# File 'app/concerns/models/party_identity.rb', line 345 def update_product_interests(product_line_ids) PartyProductInterestSync.call(self, product_line_ids) end |