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 Attribute Summary collapse
Instance Method Summary collapse
-
#call(*args) ⇒ Object
Calls the hooks with the given +args+ and returns the value of the last hooks.
-
#define(id, hook, &block) ⇒ Object
Adds a new hook.
-
#initialize(hooks = nil) ⇒ Group
constructor
Accepts an Array of +hooks+ to start with.
-
#reject!(*ids) ⇒ Object
Removes hooks matching the given +ids+.
-
#select(hook) ⇒ Object
Returns a new group for a given +hook+.
Constructor Details
#initialize(hooks = nil) ⇒ Group
Accepts an Array of +hooks+ to start with.
12 13 14 |
# File 'lib/savon/hooks/group.rb', line 12 def initialize(hooks = nil) self.hooks = hooks end |
Instance Attribute Details
#hooks ⇒ Object
18 19 20 |
# File 'lib/savon/hooks/group.rb', line 18 def hooks @hooks ||= [] end |
Instance Method Details
#call(*args) ⇒ Object
Calls the hooks with the given +args+ and returns the value of the last hooks.
40 41 42 |
# File 'lib/savon/hooks/group.rb', line 40 def call(*args) hooks.inject(nil) { |memo, hook| hook.call(*args) } end |
#define(id, hook, &block) ⇒ Object
Adds a new hook.
23 24 25 |
# File 'lib/savon/hooks/group.rb', line 23 def define(id, hook, &block) hooks << Hook.new(id, hook, &block) end |
#reject!(*ids) ⇒ Object
Removes hooks matching the given +ids+.
28 29 30 31 |
# File 'lib/savon/hooks/group.rb', line 28 def reject!(*ids) ids = ids.flatten hooks.reject! { |hook| ids.include? hook.id } end |