class Praxis::Stage
Attributes
Public Class Methods
Source
# File lib/praxis/stage.rb, line 11 def initialize(name, context, **_opts) @name = name @context = context @before_callbacks = [] @after_callbacks = [] @deferred_callbacks = Hash.new do |hash, stage| hash[stage] = { before: [], after: [] } end @stages = [] end
Public Instance Methods
Source
# File lib/praxis/stage.rb, line 73 def after(*stage_path, &block) if stage_path.any? stage_name = stage_path.shift stage = stages.find { |s| s.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
Source
# File lib/praxis/stage.rb, line 59 def before(*stage_path, &block) if stage_path.any? stage_name = stage_path.shift stage = stages.find { |s| s.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
Source
# File lib/praxis/stage.rb, line 49 def execute_callbacks(callbacks) callbacks.each do |callback| callback.call(callback_args, name: name) end end
Source
# File lib/praxis/stage.rb, line 22 def run execute_callbacks(before_callbacks) execute execute_callbacks(after_callbacks) end
Source
# File lib/praxis/stage.rb, line 32 def setup_deferred_callbacks! @deferred_callbacks.each_key do |stage_name| callbacks = @deferred_callbacks.delete stage_name callbacks[:before].each do |(*stage_path, block)| before(stage_name, *stage_path, &block) end callbacks[:after].each do |(*stage_path, block)| after(stage_name, *stage_path, &block) end end end