Class: Workarea::Login
- Inherits:
-
Object
- Object
- Workarea::Login
- Defined in:
- app/services/workarea/login.rb
Instance Attribute Summary collapse
-
#current_order ⇒ Object
readonly
Returns the value of attribute current_order.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#initialize(user, current_order) ⇒ Login
constructor
A new instance of Login.
- #perform ⇒ Object
- #previous_order ⇒ Object
Constructor Details
#initialize(user, current_order) ⇒ Login
Returns a new instance of Login.
5 6 7 8 |
# File 'app/services/workarea/login.rb', line 5 def initialize(user, current_order) @user = user @current_order = current_order end |
Instance Attribute Details
#current_order ⇒ Object (readonly)
Returns the value of attribute current_order.
3 4 5 |
# File 'app/services/workarea/login.rb', line 3 def current_order @current_order end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
3 4 5 |
# File 'app/services/workarea/login.rb', line 3 def user @user end |
Instance Method Details
#perform ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/services/workarea/login.rb', line 18 def perform user.login_success! if previous_order && !previous_order.checking_out? && previous_order.items.present? && previous_order != current_order OrderMerge.new(previous_order).merge(current_order) @current_order = previous_order elsif current_order.persisted? if current_order.started_checkout? Checkout.new(current_order).continue_as(user) else current_order.update_attributes!(user_id: user.id) end end self end |
#previous_order ⇒ Object
10 11 12 13 14 15 16 |
# File 'app/services/workarea/login.rb', line 10 def previous_order @previous_order ||= Order .carts .where(user_id: user.id) .order_by(:created_at.desc) .first end |