lib/steppy/class_methods.rb in steppy-1.0.2 vs lib/steppy/class_methods.rb in steppy-1.0.3
- old
+ new
@@ -10,25 +10,25 @@
def step_set(*sets)
steppy_cache[:sets] += sets
end
def step(method = nil, args = {}, &block)
- steps.push(
+ steps_cache.push(
Steppy.parse_step(method: method, args: args, block: block)
)
self
end
alias step_return step
def step_if(condition, &block)
- steps.push(condition: condition, block: block)
+ steps_cache.push(condition: condition, block: block)
self
end
def step_unless(condition, &block)
- steps.push(condition: -> { !steppy_run_condition(condition) }, block: block)
+ steps_cache.push(condition: -> { !steppy_run_condition(condition) }, block: block)
self
end
def step_rescue(exceptions = nil, &block)
steppy_cache[:rescues].push(exceptions: exceptions, block: block)
@@ -36,18 +36,18 @@
end
def step_if_else(condition_block, step_steps, args = {})
if_step, else_step = step_steps
- steps.push Steppy.parse_step(
+ steps_cache.push Steppy.parse_step(
method: if_step,
args: {
if: condition_block,
}.merge(args)
)
- steps.push Steppy.parse_step(
+ steps_cache.push Steppy.parse_step(
method: else_step,
args: {
unless: condition_block,
}.merge(args)
)
@@ -55,21 +55,29 @@
def step_after(key = nil, &block)
step_add_callback(:after, block, key)
end
+ def step_after_all(&block)
+ step_add_callback(:after, block, :all)
+ end
+
def step_before(key = nil, &block)
step_add_callback(:before, block, key)
end
+ def step_before_all(&block)
+ step_add_callback(:before, block, :all)
+ end
+
def step_add_callback(type, block, key)
- callback_key = key ? key.to_sym : :global
+ callback_key = key ? key.to_sym : :each
callbacks = step_callbacks[type][callback_key] ||= []
callbacks.push(block)
end
- def steps
+ def steps_cache
steppy_cache[:steps]
end
def step_callbacks
steppy_cache[:callbacks]
@@ -80,13 +88,15 @@
steps: [],
sets: [],
rescues: [],
callbacks: {
before: {
- global: [],
+ all: [],
+ each: [],
},
after: {
- global: [],
+ all: [],
+ each: [],
},
}
)
end
end