Class: Savon::Hooks::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/savon/hooks/group.rb

Overview

= Savon::Hooks::Group

Manages a list of hooks.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#hooksObject



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

#select(hook) ⇒ Object

Returns a new group for a given +hook+.



34
35
36
# File 'lib/savon/hooks/group.rb', line 34

def select(hook)
  Group.new hooks.select { |h| h.hook == hook }
end