Module: Steppy::InstanceMethods
- Defined in:
- lib/steppy/instance_methods.rb
Overview
Steppy instance methods that will be added.
Instance Attribute Summary collapse
-
#steppy_cache ⇒ Object
readonly
Returns the value of attribute steppy_cache.
Instance Method Summary collapse
- #step(method = nil, args = {}, &block) ⇒ Object (also: #step_return)
- #step_if(condition, &block) ⇒ Object
- #step_if_else(condition_block, step_steps, args = {}) ⇒ Object
- #step_rescue ⇒ Object
- #step_set(*sets) ⇒ Object
- #step_unless(condition, &block) ⇒ Object
- #steppy(attributes = {}, cache = {}) ⇒ Object
Instance Attribute Details
#steppy_cache ⇒ Object (readonly)
Returns the value of attribute steppy_cache.
6 7 8 |
# File 'lib/steppy/instance_methods.rb', line 6 def steppy_cache @steppy_cache end |
Instance Method Details
#step(method = nil, args = {}, &block) ⇒ Object Also known as: step_return
24 25 26 |
# File 'lib/steppy/instance_methods.rb', line 24 def step(method = nil, args = {}, &block) steppy_run_step Steppy.parse_step(method: method, args: args, block: block) end |
#step_if(condition, &block) ⇒ Object
48 49 50 |
# File 'lib/steppy/instance_methods.rb', line 48 def step_if(condition, &block) steppy_run_condition_block condition, block end |
#step_if_else(condition_block, step_steps, args = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/steppy/instance_methods.rb', line 30 def step_if_else(condition_block, step_steps, args = {}) if_step, else_step = step_steps steppy_run_step Steppy.parse_step( method: if_step, args: { if: condition_block, }.merge(args) ) steppy_run_step Steppy.parse_step( method: else_step, args: { unless: condition_block, }.merge(args) ) end |
#step_rescue ⇒ Object
56 57 58 |
# File 'lib/steppy/instance_methods.rb', line 56 def step_rescue(*) raise '#step_rescue can not be used in a block, please just add rescue to the #steppy block.' end |
#step_set(*sets) ⇒ Object
20 21 22 |
# File 'lib/steppy/instance_methods.rb', line 20 def step_set(*sets) steppy_sets(sets) end |
#step_unless(condition, &block) ⇒ Object
52 53 54 |
# File 'lib/steppy/instance_methods.rb', line 52 def step_unless(condition, &block) steppy_run_condition_block -> { !steppy_run_condition(condition) }, block end |
#steppy(attributes = {}, cache = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/steppy/instance_methods.rb', line 8 def steppy(attributes = {}, cache = {}) steppy_initialize_cache({ attributes: attributes, prefix: :step }.merge(cache)) if steppy_cache.key?(:block) instance_exec(&steppy_cache[:block]) else steppy_run(steppy_cache) end rescue StandardError => exception steppy_rescue exception, steppy_cache[:rescues] end |