class Praxis::Stage
Attributes
after_callbacks[R]
before_callbacks[R]
context[R]
name[R]
stages[R]
Public Class Methods
new(name, context, **opts)
click to toggle source
# File lib/praxis/stage.rb, line 15 def initialize(name, context, **opts) @name = name @context = context @before_callbacks = Array.new @after_callbacks = Array.new @deferred_callbacks = Hash.new do |hash,stage| hash[stage] = {before: [], after:[]} end @stages = Array.new end
Public Instance Methods
after(*stage_path, &block)
click to toggle source
# File lib/praxis/stage.rb, line 79 def after(*stage_path, &block) if stage_path.any? stage_name = stage_path.shift stage = stages.find { |stage| stage.name == stage_name } if stage stage.after(*stage_path, &block) else @deferred_callbacks[stage_name][:after] << [*stage_path, block] end else @after_callbacks << block end end
application()
click to toggle source
# File lib/praxis/stage.rb, line 11 def application context end
before(*stage_path, &block)
click to toggle source
# File lib/praxis/stage.rb, line 65 def before(*stage_path, &block) if stage_path.any? stage_name = stage_path.shift stage = stages.find { |stage| stage.name == stage_name } if stage stage.before(*stage_path, &block) else @deferred_callbacks[stage_name][:before] << [*stage_path, block] end else @before_callbacks << block end end
callback_args()
click to toggle source
# File lib/praxis/stage.rb, line 61 def callback_args nil end
execute()
click to toggle source
# File lib/praxis/stage.rb, line 49 def execute @stages.each do |stage| stage.run end end
execute_callbacks(callbacks)
click to toggle source
# File lib/praxis/stage.rb, line 55 def execute_callbacks(callbacks) callbacks.each do |callback| callback.call(callback_args, name: name) end end
run()
click to toggle source
# File lib/praxis/stage.rb, line 26 def run execute_callbacks(self.before_callbacks) execute execute_callbacks(self.after_callbacks) end
setup!()
click to toggle source
# File lib/praxis/stage.rb, line 32 def setup! setup_deferred_callbacks! end
setup_deferred_callbacks!()
click to toggle source
# File lib/praxis/stage.rb, line 36 def setup_deferred_callbacks! @deferred_callbacks.keys.each do |stage_name| callbacks = @deferred_callbacks.delete stage_name callbacks[:before].each do |(*stage_path, block)| self.before(stage_name, *stage_path, &block) end callbacks[:after].each do |(*stage_path, block)| self.after(stage_name, *stage_path, &block) end end end