Class: Savon::Hooks::Group
- Inherits:
-
Object
- Object
- Savon::Hooks::Group
- Defined in:
- lib/savon/hooks/group.rb
Overview
= Savon::Hooks::Group
Manages a list of hooks.
Instance Method Summary collapse
-
#call(*args) ⇒ Object
Calls the hooks with the given +args+ and returns the value of the last hooks.
-
#count ⇒ Object
Returns the number of hooks in this group.
-
#define(id, hook, &block) ⇒ Object
Adds a new hook.
-
#empty? ⇒ Boolean
Returns whether this group contains hooks.
-
#fire(hook, *args, &callback) ⇒ Object
Fire a given +hook+ with any given +args+.
-
#initialize(hooks = []) ⇒ Group
constructor
Accepts an Array of +hooks+ to start with.
-
#reject(*ids) ⇒ Object
Removes hooks matching the given +ids+.
Constructor Details
#initialize(hooks = []) ⇒ Group
Accepts an Array of +hooks+ to start with.
12 13 14 |
# File 'lib/savon/hooks/group.rb', line 12 def initialize(hooks = []) @hooks = hooks end |
Instance Method Details
#call(*args) ⇒ Object
Calls the hooks with the given +args+ and returns the value of the last hooks.
51 52 53 |
# File 'lib/savon/hooks/group.rb', line 51 def call(*args) hooks.inject(nil) { |memo, hook| hook.call(*args) } end |
#count ⇒ Object
Returns the number of hooks in this group.
22 23 24 |
# File 'lib/savon/hooks/group.rb', line 22 def count hooks.count end |
#define(id, hook, &block) ⇒ Object
Adds a new hook.
27 28 29 |
# File 'lib/savon/hooks/group.rb', line 27 def define(id, hook, &block) hooks << Hook.new(id, hook, &block) end |
#empty? ⇒ Boolean
Returns whether this group contains hooks.
17 18 19 |
# File 'lib/savon/hooks/group.rb', line 17 def empty? hooks.empty? end |
#fire(hook, *args, &callback) ⇒ Object
Fire a given +hook+ with any given +args+.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/savon/hooks/group.rb', line 38 def fire(hook, *args, &callback) callable = select(hook) if callable.empty? callback.call else args.unshift(callback) if callback callable.call(*args) end end |
#reject(*ids) ⇒ Object
Removes hooks matching the given +ids+.
32 33 34 35 |
# File 'lib/savon/hooks/group.rb', line 32 def reject(*ids) ids = ids.flatten hooks.reject! { |hook| ids.include? hook.id } end |