Class: Savon::Hooks::Hook
- Inherits:
-
Object
- Object
- Savon::Hooks::Hook
- Defined in:
- lib/savon/hooks/hook.rb
Overview
= Savon::Hooks::Hook
A hook used somewhere in the system.
Constant Summary collapse
- HOOKS =
[ # :soap_request # # Around filter wrapping the POST request executed to call a SOAP service. # See: Savon::SOAP::Request#response # # Arguments # # [callback] A block to execute the SOAP request # [request] The current <tt>Savon::SOAP::Request</tt> # # Examples # # Log the time before and after the SOAP call: # # Savon.config.hooks.define(:my_hook, :soap_request) do |callback, request| # Timer.log(:start, Time.now) # response = callback.call # Timer.log(:end, Time.now) # response # end # # Replace the SOAP call and return a custom response: # # Savon.config.hooks.define(:mock_hook, :soap_request) do |_, request| # HTTPI::Response.new(200, {}, "") # end :soap_request ]
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#hook ⇒ Object
Returns the value of attribute hook.
-
#id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
-
#call(*args) ⇒ Object
Calls the +block+ with the given +args+.
-
#initialize(id, hook, &block) ⇒ Hook
constructor
Expects an +id+, the name of the +hook+ to use and a +block+ to be called.
Constructor Details
#initialize(id, hook, &block) ⇒ Hook
Expects an +id+, the name of the +hook+ to use and a +block+ to be called.
42 43 44 45 46 47 48 49 50 |
# File 'lib/savon/hooks/hook.rb', line 42 def initialize(id, hook, &block) unless HOOKS.include?(hook) raise ArgumentError, "No such hook: #{hook}. Expected one of: #{HOOKS.join(', ')}" end self.id = id self.hook = hook self.block = block end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
52 53 54 |
# File 'lib/savon/hooks/hook.rb', line 52 def block @block end |
#hook ⇒ Object
Returns the value of attribute hook.
52 53 54 |
# File 'lib/savon/hooks/hook.rb', line 52 def hook @hook end |
#id ⇒ Object
Returns the value of attribute id.
52 53 54 |
# File 'lib/savon/hooks/hook.rb', line 52 def id @id end |
Instance Method Details
#call(*args) ⇒ Object
Calls the +block+ with the given +args+.
55 56 57 |
# File 'lib/savon/hooks/hook.rb', line 55 def call(*args) block.call(*args) end |