Class: Query::PartyScopedOpportunities

Inherits:
Object
  • Object
show all
Defined in:
app/services/query/party_scoped_opportunities.rb

Overview

Builds the union of opportunities related to a party, branching on whether
the party is a Customer or a Contact:

Customer: customer_id, contact_id, or participant party_id ∈ self+contacts
Contact (with customer): contact, customer, or participant ∈ customer
Contact (orphan): contact, or participant = contact

Returns an Opportunity relation usable in further .where/.order calls.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(party) ⇒ PartyScopedOpportunities

Returns a new instance of PartyScopedOpportunities.



16
17
18
# File 'app/services/query/party_scoped_opportunities.rb', line 16

def initialize(party)
  @party = party
end

Class Method Details

.call(party) ⇒ Object



12
13
14
# File 'app/services/query/party_scoped_opportunities.rb', line 12

def self.call(party)
  new(party).call
end

Instance Method Details

#callObject



20
21
22
23
24
25
26
# File 'app/services/query/party_scoped_opportunities.rb', line 20

def call
  if @party.is_a?(Customer)
    customer_scope
  else
    contact_scope
  end
end