Module ActionWebService::Invocation::ClassMethods
In: actionwebservice/lib/action_web_service/invocation.rb

Invocation interceptors provide a means to execute custom code before and after method invocations on ActionWebService::Base objects.

When running in Direct dispatching mode, ActionController filters should be used for this functionality instead.

The semantics of invocation interceptors are the same as ActionController filters, and accept the same parameters and options.

A before interceptor can also cancel execution by returning false, or returning a [false, "cancel reason"] array if it wishes to supply a reason for canceling the request.

Example

  class CustomService < ActionWebService::Base
    before_invocation :intercept_add, :only => [:add]

    def add(a, b)
      a + b
    end

    private
      def intercept_add
        return [false, "permission denied"] # cancel it
      end
  end

Options:

:except
A list of methods for which the interceptor will NOT be called
:only
A list of methods for which the interceptor WILL be called

Methods

Public Instance methods

after_invocation(*interceptors, &block)

Appends the given interceptors to be called after method invocation.

[Source]

# File actionwebservice/lib/action_web_service/invocation.rb, line 65
      def append_after_invocation(*interceptors, &block)
        conditions = extract_conditions!(interceptors)
        interceptors << block if block_given?
        add_interception_conditions(interceptors, conditions)
        append_interceptors_to_chain("after", interceptors)
      end

Appends the given interceptors to be called before method invocation.

[Source]

# File actionwebservice/lib/action_web_service/invocation.rb, line 45
      def append_before_invocation(*interceptors, &block)
        conditions = extract_conditions!(interceptors)
        interceptors << block if block_given?
        add_interception_conditions(interceptors, conditions)
        append_interceptors_to_chain("before", interceptors)
      end
before_invocation(*interceptors, &block)

Prepends the given interceptors to be called after method invocation.

[Source]

# File actionwebservice/lib/action_web_service/invocation.rb, line 74
      def prepend_after_invocation(*interceptors, &block)
        conditions = extract_conditions!(interceptors)
        interceptors << block if block_given?
        add_interception_conditions(interceptors, conditions)
        prepend_interceptors_to_chain("after", interceptors)
      end

Prepends the given interceptors to be called before method invocation.

[Source]

# File actionwebservice/lib/action_web_service/invocation.rb, line 54
      def prepend_before_invocation(*interceptors, &block)
        conditions = extract_conditions!(interceptors)
        interceptors << block if block_given?
        add_interception_conditions(interceptors, conditions)
        prepend_interceptors_to_chain("before", interceptors)
      end

Private Instance methods

[Source]

# File actionwebservice/lib/action_web_service/invocation.rb, line 114
        def add_interception_conditions(interceptors, conditions)
          return unless conditions
          included, excluded = conditions[:only], conditions[:except]
          write_inheritable_hash("included_intercepted_methods", condition_hash(interceptors, included)) && return if included
          write_inheritable_hash("excluded_intercepted_methods", condition_hash(interceptors, excluded)) if excluded
        end

[Source]

# File actionwebservice/lib/action_web_service/invocation.rb, line 100
        def append_interceptors_to_chain(condition, interceptors)
          write_inheritable_array("#{condition}_invocation_interceptors", interceptors)
        end

[Source]

# File actionwebservice/lib/action_web_service/invocation.rb, line 121
        def condition_hash(interceptors, *methods)
          interceptors.inject({}) {|hash, interceptor| hash.merge(interceptor => methods.flatten.map {|method| method.to_s})}
        end

[Source]

# File actionwebservice/lib/action_web_service/invocation.rb, line 109
        def extract_conditions!(interceptors)
          return nil unless interceptors.last.is_a? Hash
          interceptors.pop
        end

[Source]

# File actionwebservice/lib/action_web_service/invocation.rb, line 104
        def prepend_interceptors_to_chain(condition, interceptors)
          interceptors = interceptors + read_inheritable_attribute("#{condition}_invocation_interceptors")
          write_inheritable_attribute("#{condition}_invocation_interceptors", interceptors)
        end

[Validate]