Class: CheckoutProcessor
- Inherits:
-
Struct
- Object
- Struct
- CheckoutProcessor
- Defined in:
- app/models/job/checkout_processor.rb
Overview
This class excapsulate asynchrnous things we can do during or immediately following checkout usually involving the payment or customer objects (which aren’t available after checkout) Examples: Updating a patron phone or address
This class is not for order-related processing things. See OrderProcessor for that
This class WILL NOT RUN ASYNC in test envs
Constant Summary collapse
- QUEUE =
"checkout"
Instance Attribute Summary collapse
-
#address_hash ⇒ Object
Returns the value of attribute address_hash.
-
#checkout_name ⇒ Object
Returns the value of attribute checkout_name.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#person ⇒ Object
Returns the value of attribute person.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#time_zone ⇒ Object
Returns the value of attribute time_zone.
Class Method Summary collapse
Instance Method Summary collapse
- #address_exists? ⇒ Boolean
-
#initialize(person, customer, address, phone, time_zone, checkout_name = "checkout") ⇒ CheckoutProcessor
constructor
A new instance of CheckoutProcessor.
- #perform ⇒ Object
- #run_now? ⇒ Boolean
Constructor Details
#initialize(person, customer, address, phone, time_zone, checkout_name = "checkout") ⇒ CheckoutProcessor
Returns a new instance of CheckoutProcessor.
13 14 15 16 17 18 19 20 21 |
# File 'app/models/job/checkout_processor.rb', line 13 def initialize(person, customer, address, phone, time_zone, checkout_name = "checkout") self.person = person self.first_name = customer.first_name self.last_name = customer.last_name self.address_hash = address.attributes. unless address.nil? self.phone = phone self.time_zone = time_zone self.checkout_name = checkout_name end |
Instance Attribute Details
#address_hash ⇒ Object
Returns the value of attribute address_hash
10 11 12 |
# File 'app/models/job/checkout_processor.rb', line 10 def address_hash @address_hash end |
#checkout_name ⇒ Object
Returns the value of attribute checkout_name
10 11 12 |
# File 'app/models/job/checkout_processor.rb', line 10 def checkout_name @checkout_name end |
#first_name ⇒ Object
Returns the value of attribute first_name
10 11 12 |
# File 'app/models/job/checkout_processor.rb', line 10 def first_name @first_name end |
#last_name ⇒ Object
Returns the value of attribute last_name
10 11 12 |
# File 'app/models/job/checkout_processor.rb', line 10 def last_name @last_name end |
#person ⇒ Object
Returns the value of attribute person
10 11 12 |
# File 'app/models/job/checkout_processor.rb', line 10 def person @person end |
#phone ⇒ Object
Returns the value of attribute phone
10 11 12 |
# File 'app/models/job/checkout_processor.rb', line 10 def phone @phone end |
#time_zone ⇒ Object
Returns the value of attribute time_zone
10 11 12 |
# File 'app/models/job/checkout_processor.rb', line 10 def time_zone @time_zone end |
Class Method Details
.process(person, customer, address, phone, time_zone, checkout_name) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'app/models/job/checkout_processor.rb', line 23 def self.process(person, customer, address, phone, time_zone, checkout_name) job = CheckoutProcessor.new(person, customer, address, phone, time_zone, checkout_name) if job.run_now? job.perform else Delayed::Job.enqueue job, :queue => QUEUE end end |
Instance Method Details
#address_exists? ⇒ Boolean
43 44 45 |
# File 'app/models/job/checkout_processor.rb', line 43 def address_exists? self.address_hash.present? && self.address_hash.values.select{|values| values.present?}.any? end |
#perform ⇒ Object
33 34 35 36 37 |
# File 'app/models/job/checkout_processor.rb', line 33 def perform self.person.update_name(self.first_name, self.last_name) self.person.update_address(self.address_hash, self.time_zone, nil, checkout_name) if address_exists? self.person.add_phone_if_missing(self.phone) end |
#run_now? ⇒ Boolean
39 40 41 |
# File 'app/models/job/checkout_processor.rb', line 39 def run_now? Rails.env.test? end |