Class: Minfra::Cli::Hook::Hooker
- Inherits:
-
Object
- Object
- Minfra::Cli::Hook::Hooker
show all
- Includes:
- Logging
- Defined in:
- lib/minfra/cli/hook.rb
Instance Method Summary
collapse
Methods included from Logging
#debug, #deprecated, #error, #exit_error, #info, #warn
Constructor Details
#initialize(klass) ⇒ Hooker
Returns a new instance of Hooker.
62
63
64
65
|
# File 'lib/minfra/cli/hook.rb', line 62
def initialize(klass)
@klass = klass
@hooks = []
end
|
Instance Method Details
#call_after_hooks(obj, names) ⇒ Object
82
83
84
85
86
87
88
|
# File 'lib/minfra/cli/hook.rb', line 82
def call_after_hooks(obj, names)
@hooks.select { |h| h.match?(:after, names) }.each do |h|
debug("Hook after: #{names.join(',')}")
h.exec(obj)
end
end
|
#call_before_hooks(obj, names) ⇒ Object
75
76
77
78
79
80
|
# File 'lib/minfra/cli/hook.rb', line 75
def call_before_hooks(obj, names)
@hooks.select { |h| h.match?(:before, names) }.each do |h|
debug("Hook before: #{names.join(',')}")
h.exec(obj)
end
end
|
#register_after(names, block) ⇒ Object
71
72
73
|
# File 'lib/minfra/cli/hook.rb', line 71
def register_after(names, block)
@hooks << Hook.new(:after, names, block)
end
|
#register_before(names, block) ⇒ Object
67
68
69
|
# File 'lib/minfra/cli/hook.rb', line 67
def register_before(names, block)
@hooks << Hook.new(:before, names, block)
end
|