Module: Thor::Hooks::ClassMethods

Defined in:
lib/web_crawler/cli/thor_hooks.rb

Instance Method Summary collapse

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)
  options = args.last.is_a?(Hash) ? args.pop : { }
  check_hooks_options! options
  add_hook :after, args, options, &block
end

#after_hooksObject



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)
  options = args.last.is_a?(Hash) ? args.pop : { }
  check_hooks_options! options
  add_hook :before, args, options, &block
end

#before_hooksObject



35
36
37
# File 'lib/web_crawler/cli/thor_hooks.rb', line 35

def before_hooks
  hooks[:before]
end

#hooksObject



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