Class: Munificent::ExistingDonatorFinder

Inherits:
Object
  • Object
show all
Defined in:
app/services/munificent/existing_donator_finder.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_donator:, email_address:) ⇒ ExistingDonatorFinder

Returns a new instance of ExistingDonatorFinder.



7
8
9
10
11
12
13
14
# File 'app/services/munificent/existing_donator_finder.rb', line 7

def initialize(current_donator:, email_address:)
  if current_donator.blank? && email_address.blank?
    raise ArgumentError, "You must provide either an email address or a current donator"
  end

  @current_donator = current_donator
  @email_address = email_address
end

Class Method Details

.findObject



3
4
5
# File 'app/services/munificent/existing_donator_finder.rb', line 3

def self.find(...)
  new(...).find
end

Instance Method Details

#findObject



16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/munificent/existing_donator_finder.rb', line 16

def find
  if email_address_not_provided?
    no_choice_but_to_use_current_donator
  elsif current_donator_not_provided?
    prefer_confirmed_donator_but_accept_unconfirmed_donator
  elsif established_current_donator?
    always_use_established_current_donator
  else
    prefer_confirmed_donator_but_accept_new_donator
  end
end