Module: ActionService::Invocation::ClassMethods

Defined in:
lib/action_service/invocation.rb

Overview

Invocation interceptors provide a means to execute custom code before and after API method invocations on ActionService::Base objects when running in Delegated dispatching mode.

When running in Direct mode, ActionController filters should be used 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 < ActionService::Base
  before_invocation :intercept_add, :only => [:add]

  def add(a, b)
    a + b
  end

  export :add, :expects => [Integer, Integer], :returns => [Integer]

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

Options:

:except

A list of exports to which the interceptor will NOT apply

:only

A list of exports to which the interceptor will apply

Instance Method Summary collapse

Instance Method Details

#after_invocation_interceptorsObject

:nodoc:



95
96
97
# File 'lib/action_service/invocation.rb', line 95

def after_invocation_interceptors # :nodoc:
  read_inheritable_attribute("after_invocation_interceptors")
end

#append_after_invocation(*interceptors, &block) ⇒ Object Also known as: after_invocation

Appends the given interceptors to be called after method invocation.



73
74
75
76
77
78
# File 'lib/action_service/invocation.rb', line 73

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

#append_before_invocation(*interceptors, &block) ⇒ Object Also known as: before_invocation

Appends the given interceptors to be called before method invocation.



53
54
55
56
57
58
# File 'lib/action_service/invocation.rb', line 53

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_interceptorsObject

:nodoc:



91
92
93
# File 'lib/action_service/invocation.rb', line 91

def before_invocation_interceptors # :nodoc:
  read_inheritable_attribute("before_invocation_interceptors")
end

#excluded_intercepted_methodsObject

:nodoc:



103
104
105
# File 'lib/action_service/invocation.rb', line 103

def excluded_intercepted_methods # :nodoc:
  read_inheritable_attribute("excluded_intercepted_methods") || {}
end

#included_intercepted_methodsObject

:nodoc:



99
100
101
# File 'lib/action_service/invocation.rb', line 99

def included_intercepted_methods # :nodoc:
  read_inheritable_attribute("included_intercepted_methods") || {}
end

#prepend_after_invocation(*interceptors, &block) ⇒ Object

Prepends the given interceptors to be called after method invocation.



82
83
84
85
86
87
# File 'lib/action_service/invocation.rb', line 82

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

#prepend_before_invocation(*interceptors, &block) ⇒ Object

Prepends the given interceptors to be called before method invocation.



62
63
64
65
66
67
# File 'lib/action_service/invocation.rb', line 62

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