Class: Verifly::ApplicatorWithOptions
- Inherits:
-
Object
- Object
- Verifly::ApplicatorWithOptions
- Defined in:
- lib/verifly/applicator_with_options.rb
Overview
An applicator with useful options
Direct Known Subclasses
Instance Attribute Summary collapse
-
#action ⇒ Applicator
main action to apply on call.
-
#if_condition ⇒ Applicator
main action only apply if condition evaluates to truthy value.
-
#unless_condition ⇒ Applicator
main action only apply if condition evaluates to falsey value.
Instance Method Summary collapse
-
#call(binding_, *context) ⇒ Object
Applies main action if if_condition is evaluated to truthy value and unless_condition is evaluated to falsey value.
-
#initialize(action = block, options = {}, &block) ⇒ ApplicatorWithOptions
constructor
A new instance of ApplicatorWithOptions.
Constructor Details
#initialize(action = block, options = {}, &block) ⇒ ApplicatorWithOptions
Returns a new instance of ApplicatorWithOptions.
26 27 28 29 30 31 32 |
# File 'lib/verifly/applicator_with_options.rb', line 26 def initialize(*args, &block) action, = (*args, &block) self.action = Applicator.build(action) self.if_condition = Applicator.build(.fetch(:if, true)) self.unless_condition = Applicator.build(.fetch(:unless, false)) end |
Instance Attribute Details
#action ⇒ Applicator
main action to apply on call
15 16 17 |
# File 'lib/verifly/applicator_with_options.rb', line 15 def action @action end |
#if_condition ⇒ Applicator
main action only apply if condition evaluates to truthy value
15 16 17 |
# File 'lib/verifly/applicator_with_options.rb', line 15 def if_condition @if_condition end |
#unless_condition ⇒ Applicator
main action only apply if condition evaluates to falsey value
15 16 17 |
# File 'lib/verifly/applicator_with_options.rb', line 15 def unless_condition @unless_condition end |
Instance Method Details
#call(binding_, *context) ⇒ Object
Applies main action if if_condition is evaluated to truthy value and unless_condition is evaluated to falsey value
42 43 44 45 46 |
# File 'lib/verifly/applicator_with_options.rb', line 42 def call(binding_, *context) return unless if_condition.call(binding_, *context) return if unless_condition.call(binding_, *context) action.call(binding_, *context) end |