Module: Fetch::Callbacks::ClassMethods
- Defined in:
- lib/fetch/callbacks.rb
Instance Method Summary collapse
-
#callbacks ⇒ Object
Hash of callback blocks to be called.
-
#define_callback(*names) ⇒ Object
Defines callback methods on the class level.
- #inherited(base) ⇒ Object
Instance Method Details
#callbacks ⇒ Object
Hash of callback blocks to be called.
42 43 44 |
# File 'lib/fetch/callbacks.rb', line 42 def callbacks @callbacks ||= Hash.new { |h, k| h[k] = [] } end |
#define_callback(*names) ⇒ Object
Defines callback methods on the class level.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fetch/callbacks.rb', line 47 def define_callback(*names) = names.last.is_a?(Hash) ? names.pop : {} reverse = !![:reverse] 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, reverse).last end define_method "#{name}!" do |*args| run_last_callback_for(name, args, reverse) end end end |
#inherited(base) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/fetch/callbacks.rb', line 66 def inherited(base) super callbacks.each do |name, callbacks| base.callbacks[name] = callbacks.dup end end |