Module: Fetch::Callbacks::ClassMethods

Defined in:
lib/fetch/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#callbacksObject

Hash of callback blocks to be called.



36
37
38
# File 'lib/fetch/callbacks.rb', line 36

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

#define_callback(*names) ⇒ Object

Defines callback methods on the class level.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fetch/callbacks.rb', line 41

def define_callback(*names)
  names.each do |name|
    define_singleton_method name do |*values, &block|
      create_callback_for(name, *values, &block)
    end

    define_method name do |*args|
      run_callbacks_for(name, *args).last
    end

    define_method "#{name}!" do |*args|
      run_last_callback_for(name, *args)
    end
  end
end

#inherited(base) ⇒ Object



57
58
59
60
61
62
# File 'lib/fetch/callbacks.rb', line 57

def inherited(base)
  super
  callbacks.each do |name, callbacks|
    base.callbacks[name] = callbacks.dup
  end
end