Module: LinkChecker::Callbacks

Included in:
Checker, Task, Tasks
Defined in:
lib/ruby-link-checker/callbacks.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/ruby-link-checker/callbacks.rb', line 23

def method_missing(m, *args, &block)
  if m.to_s[-1] == '!'
    callback(m.to_s[...-1].to_sym, *args)
  else
    super
  end
end

Instance Method Details

#callbacksObject



5
6
7
# File 'lib/ruby-link-checker/callbacks.rb', line 5

def callbacks
  @callbacks ||= Hash.new { |h, k| h[k] = [] }
end

#delegatesObject



9
10
11
# File 'lib/ruby-link-checker/callbacks.rb', line 9

def delegates
  @delegates ||= []
end

#on(*events, &block) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/ruby-link-checker/callbacks.rb', line 13

def on(*events, &block)
  if events && Array(events).any?
    Array(events).each do |event|
      callbacks[event.to_s] << block
    end
  else
    delegates << block
  end
end