forked from savonrb/savon
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
117 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require "savon/hooks/hook" | ||
|
||
module Savon | ||
module Hooks | ||
|
||
# = Savon::Hooks::Group | ||
# | ||
# Manages a list of hooks. | ||
class Group | ||
|
||
# Accepts an Array of +hooks+ to start with. | ||
def initialize(hooks = nil) | ||
self.hooks = hooks | ||
end | ||
|
||
attr_writer :hooks | ||
|
||
def hooks | ||
@hooks ||= [] | ||
end | ||
|
||
# Adds a new hook. | ||
def define(id, hook, &block) | ||
hooks << Hook.new(id, hook, &block) | ||
end | ||
|
||
# Removes hooks matching the given +ids+. | ||
def reject!(*ids) | ||
ids = ids.flatten | ||
hooks.reject! { |hook| ids.include? hook.id } | ||
end | ||
|
||
# Returns a new group for a given +hook+. | ||
def select(hook) | ||
Group.new hooks.select { |h| h.hook == hook } | ||
end | ||
|
||
# Calls the hooks with the given +args+ and returns the | ||
# value of the last hooks. | ||
def call(*args) | ||
hooks.inject(nil) { |memo, hook| hook.call(*args) } | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Savon | ||
module Hooks | ||
|
||
# = Savon::Hooks::Hook | ||
# | ||
# A hook used somewhere in the system. | ||
class Hook | ||
|
||
HOOKS = [ | ||
|
||
# Replaces the POST request executed to call a service. | ||
# See: Savon::SOAP::Request#response | ||
# | ||
# Receives the <tt>Savon::SOAP::Request</tt> and is expected to return an <tt>HTTPI::Response</tt>. | ||
# It can change the request and return something falsy to still execute the POST request. | ||
:soap_request | ||
|
||
] | ||
|
||
# Expects an +id+, the name of the +hook+ to use and a +block+ to be called. | ||
def initialize(id, hook, &block) | ||
self.id = id | ||
self.hook = hook | ||
self.block = block | ||
end | ||
|
||
attr_accessor :id, :hook, :block | ||
|
||
# Calls the +block+ with the given +args+. | ||
def call(*args) | ||
block.call(*args) | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Savon | ||
|
||
Version = "0.9.7" | ||
Version = "1.0.0" | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters