Class: Stall::Checkout::Step
- Inherits:
-
Object
- Object
- Stall::Checkout::Step
- Defined in:
- lib/stall/checkout/step.rb
Direct Known Subclasses
InformationsCheckoutStep, PaymentCheckoutStep, PaymentReturnCheckoutStep
Instance Attribute Summary collapse
-
#cart ⇒ Object
readonly
Returns the value of attribute cart.
Instance Method Summary collapse
-
#allow_inactive_carts? ⇒ Boolean
Allows subclasses to override this value with ‘true` to allow paid carts to be processed by that step too.
- #identifier ⇒ Object
-
#initialize(cart) ⇒ Step
constructor
A new instance of Step.
-
#inject(method, content) ⇒ Object
Allow injecting dependencies on step initialization and accessing them as instance method in subclasses.
- #is?(key) ⇒ Boolean
-
#prepare ⇒ Object
Allows for preparing to the cart for the current step before rendering the step’s view.
- #process ⇒ Object
-
#save ⇒ Object
Abstracts the simple case of assigning the submitted parameters to the cart object, running the step validations and saving the cart.
- #skip? ⇒ Boolean
-
#valid? ⇒ Boolean
Run cart validations then step validations, and cart validations, returning wether they’re both valid or not, allowing to display all involved errors to the visitor in one time.
Constructor Details
#initialize(cart) ⇒ Step
Returns a new instance of Step.
10 11 12 |
# File 'lib/stall/checkout/step.rb', line 10 def initialize(cart) @cart = cart end |
Instance Attribute Details
#cart ⇒ Object (readonly)
Returns the value of attribute cart.
8 9 10 |
# File 'lib/stall/checkout/step.rb', line 8 def cart @cart end |
Instance Method Details
#allow_inactive_carts? ⇒ Boolean
Allows subclasses to override this value with ‘true` to allow paid carts to be processed by that step too.
Returning false redirects the user telling him that his cart is empty
By default, the ‘PaymentReturn` checkout step returns true, since it’s always called after the cart is paid
55 56 57 |
# File 'lib/stall/checkout/step.rb', line 55 def allow_inactive_carts? false end |
#identifier ⇒ Object
40 41 42 43 44 45 |
# File 'lib/stall/checkout/step.rb', line 40 def identifier @identifier ||= begin class_name = self.class.name.demodulize class_name.gsub(/CheckoutStep$/, '').underscore.to_sym end end |
#inject(method, content) ⇒ Object
Allow injecting dependencies on step initialization and accessing them as instance method in subclasses
16 17 18 |
# File 'lib/stall/checkout/step.rb', line 16 def inject(method, content) define_singleton_method(method, -> { content }) end |
#is?(key) ⇒ Boolean
36 37 38 |
# File 'lib/stall/checkout/step.rb', line 36 def is?(key) identifier == key end |
#prepare ⇒ Object
Allows for preparing to the cart for the current step before rendering the step’s view
Note : Meant to be overriden by subclasses
25 26 |
# File 'lib/stall/checkout/step.rb', line 25 def prepare end |
#process ⇒ Object
28 29 30 |
# File 'lib/stall/checkout/step.rb', line 28 def process save end |
#save ⇒ Object
Abstracts the simple case of assigning the submitted parameters to the cart object, running the step validations and saving the cart
71 72 73 74 |
# File 'lib/stall/checkout/step.rb', line 71 def save cart.assign_attributes(cart_params) cart.save if valid? end |
#skip? ⇒ Boolean
32 33 34 |
# File 'lib/stall/checkout/step.rb', line 32 def skip? false end |
#valid? ⇒ Boolean
Run cart validations then step validations, and cart validations, returning wether they’re both valid or not, allowing to display all involved errors to the visitor in one time
62 63 64 65 66 67 |
# File 'lib/stall/checkout/step.rb', line 62 def valid? cart.validate run_step_validations!(clear: false) cart.errors.empty? end |