Class: Spree::Checkout::Requirement
- Inherits:
-
Object
- Object
- Spree::Checkout::Requirement
- Defined in:
- app/models/spree/checkout/requirement.rb
Overview
Instance Attribute Summary collapse
-
#field ⇒ String
readonly
Field identifier (e.g. “po_number”, “tax_id”).
-
#message ⇒ String
readonly
Human-readable message shown when the requirement is not met.
-
#step ⇒ String
readonly
Checkout step this requirement belongs to.
Instance Method Summary collapse
-
#applicable?(order) ⇒ Boolean
Whether this requirement applies to the given order.
-
#initialize(step:, field:, message:, satisfied:, applicable: ->(_) { true }) ⇒ Requirement
constructor
A new instance of Requirement.
-
#satisfied?(order) ⇒ Boolean
Whether the requirement has been met.
Constructor Details
#initialize(step:, field:, message:, satisfied:, applicable: ->(_) { true }) ⇒ Requirement
Returns a new instance of Requirement.
32 33 34 35 36 37 38 |
# File 'app/models/spree/checkout/requirement.rb', line 32 def initialize(step:, field:, message:, satisfied:, applicable: ->(_) { true }) @step = step.to_s @field = field.to_s @message = @satisfied_proc = satisfied @applicable_proc = applicable end |
Instance Attribute Details
#field ⇒ String (readonly)
Returns field identifier (e.g. “po_number”, “tax_id”).
21 22 23 |
# File 'app/models/spree/checkout/requirement.rb', line 21 def field @field end |
#message ⇒ String (readonly)
Returns human-readable message shown when the requirement is not met.
24 25 26 |
# File 'app/models/spree/checkout/requirement.rb', line 24 def @message end |
#step ⇒ String (readonly)
Returns checkout step this requirement belongs to.
18 19 20 |
# File 'app/models/spree/checkout/requirement.rb', line 18 def step @step end |
Instance Method Details
#applicable?(order) ⇒ Boolean
Returns whether this requirement applies to the given order.
46 |
# File 'app/models/spree/checkout/requirement.rb', line 46 def applicable?(order) = @applicable_proc.call(order) |
#satisfied?(order) ⇒ Boolean
Returns whether the requirement has been met.
42 |
# File 'app/models/spree/checkout/requirement.rb', line 42 def satisfied?(order) = @satisfied_proc.call(order) |