Module: Thor::Hooks::ClassMethods
- Defined in:
- lib/web_crawler/cli/thor_hooks.rb
Instance Method Summary collapse
- #after_action(*args, &block) ⇒ Object
- #after_hooks ⇒ Object
- #before_action(*args, &block) ⇒ Object
- #before_hooks ⇒ Object
- #hooks ⇒ Object
- #render(*args, &block) ⇒ Object
- #run_hooks(place, instance, task) ⇒ Object
Instance Method Details
#after_action(*args, &block) ⇒ Object
49 50 51 52 53 |
# File 'lib/web_crawler/cli/thor_hooks.rb', line 49 def after_action(*args, &block) = args.last.is_a?(Hash) ? args.pop : { } add_hook :after, args, , &block end |
#after_hooks ⇒ Object
39 40 41 |
# File 'lib/web_crawler/cli/thor_hooks.rb', line 39 def after_hooks hooks[:after] end |
#before_action(*args, &block) ⇒ Object
43 44 45 46 47 |
# File 'lib/web_crawler/cli/thor_hooks.rb', line 43 def before_action(*args, &block) = args.last.is_a?(Hash) ? args.pop : { } add_hook :before, args, , &block end |
#before_hooks ⇒ Object
35 36 37 |
# File 'lib/web_crawler/cli/thor_hooks.rb', line 35 def before_hooks hooks[:before] end |
#hooks ⇒ Object
31 32 33 |
# File 'lib/web_crawler/cli/thor_hooks.rb', line 31 def hooks @@hooks ||= { before: [], after: [] } end |
#render(*args, &block) ⇒ Object
55 56 57 58 59 |
# File 'lib/web_crawler/cli/thor_hooks.rb', line 55 def render(*args, &block) after_action(*args) do block.call @task_result, @options end end |
#run_hooks(place, instance, task) ⇒ Object
61 62 63 |
# File 'lib/web_crawler/cli/thor_hooks.rb', line 61 def run_hooks(place, instance, task) hooks[place].each { |hook| self.run_hook(instance, task, hook) } end |