Class: Polyrun::Hooks::Dsl::Registry
- Inherits:
-
Object
- Object
- Polyrun::Hooks::Dsl::Registry
- Defined in:
- lib/polyrun/hooks/dsl.rb
Instance Method Summary collapse
- #add(phase, proc) ⇒ Object
- #any?(phase) ⇒ Boolean
- #empty? ⇒ Boolean
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #run(phase, env) ⇒ Object
- #worker_hooks? ⇒ Boolean
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
17 18 19 |
# File 'lib/polyrun/hooks/dsl.rb', line 17 def initialize @phases = Hash.new { |h, k| h[k] = [] } end |
Instance Method Details
#add(phase, proc) ⇒ Object
21 22 23 |
# File 'lib/polyrun/hooks/dsl.rb', line 21 def add(phase, proc) @phases[phase.to_sym] << proc end |
#any?(phase) ⇒ Boolean
30 31 32 |
# File 'lib/polyrun/hooks/dsl.rb', line 30 def any?(phase) @phases[phase.to_sym].any? end |
#empty? ⇒ Boolean
34 35 36 |
# File 'lib/polyrun/hooks/dsl.rb', line 34 def empty? @phases.values.all?(&:empty?) end |
#run(phase, env) ⇒ Object
26 27 28 |
# File 'lib/polyrun/hooks/dsl.rb', line 26 def run(phase, env) @phases[phase.to_sym].each { |pr| pr.call(env) } end |
#worker_hooks? ⇒ Boolean
38 39 40 |
# File 'lib/polyrun/hooks/dsl.rb', line 38 def worker_hooks? any?(:before_worker) || any?(:after_worker) end |