Module: PartySearch
- Extended by:
- ActiveSupport::Concern
- Included in:
- Party
- Defined in:
- app/models/concerns/party_search.rb
Overview
Full-text (pg_search) and relational search scopes for Party: composite name
search, phone/email/address fragments, and “searchable” subsets for CRM quick search.
Class Method Summary collapse
-
.active ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are active.
-
.address_search ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are address search.
-
.customer_or_contact ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are customer or contact.
-
.email_search ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are email search.
-
.inactive ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are inactive.
-
.lookup ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are lookup.
-
.phone_search ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are phone search.
-
.ransackable_scopes(_auth_object = nil) ⇒ Array<Symbol>
Scopes allowed for Ransack on party search forms.
-
.searchable ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are searchable.
-
.with_main_address ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are with main address.
Class Method Details
.active ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are active. Active Record Scope
55 |
# File 'app/models/concerns/party_search.rb', line 55 scope :active, -> { where(inactive: [false, nil]) } |
.address_search ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are address search. Active Record Scope
61 |
# File 'app/models/concerns/party_search.rb', line 61 scope :address_search, ->(query) { searchable.joins(:addresses).merge(Address.address_search(query)) } |
.customer_or_contact ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are customer or contact. Active Record Scope
68 |
# File 'app/models/concerns/party_search.rb', line 68 scope :customer_or_contact, -> { where("parties.type in ('Customer','Contact')") } |
.email_search ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are email search. Active Record Scope
60 |
# File 'app/models/concerns/party_search.rb', line 60 scope :email_search, ->(query) { searchable.joins(:contact_points).merge(ContactPoint.emails.contains(query)) } |
.inactive ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are inactive. Active Record Scope
54 |
# File 'app/models/concerns/party_search.rb', line 54 scope :inactive, -> { where(inactive: true) } |
.lookup ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are lookup. Active Record Scope
72 |
# File 'app/models/concerns/party_search.rb', line 72 scope :lookup, ->(query) { searchable.composite_search(query) } |
.phone_search ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are phone search. Active Record Scope
57 58 59 |
# File 'app/models/concerns/party_search.rb', line 57 scope :phone_search, lambda { |query| PhoneNumber.parse_and_format(query) ? searchable.joins(:contact_points).merge(ContactPoint.dialable.contains(query.to_s)) : searchable.none } |
.ransackable_scopes(_auth_object = nil) ⇒ Array<Symbol>
Scopes allowed for Ransack on party search forms.
81 82 83 |
# File 'app/models/concerns/party_search.rb', line 81 def ransackable_scopes(_auth_object = nil) %i[lookup banner_search] end |
.searchable ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are searchable. Active Record Scope
63 64 65 66 67 |
# File 'app/models/concerns/party_search.rb', line 63 scope :searchable, lambda { where.not(inactive: true).where( "(parties.type = 'Customer' AND (parties.state IS NULL OR parties.state NOT IN ('guest','inactive'))) OR parties.type <> 'Customer'" ) } |
.with_main_address ⇒ ActiveRecord::Relation<PartySearch>
A relation of PartySearches that are with main address. Active Record Scope
69 70 71 |
# File 'app/models/concerns/party_search.rb', line 69 scope :with_main_address, lambda { joins('left join addresses main_address on main_address.id = COALESCE(parties.mailing_address_id, parties.shipping_address_id, parties.billing_address_id)') } |