Module: ActionService::Invocation::InstanceMethods

Defined in:
lib/action_service/invocation.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.append_features(base) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/action_service/invocation.rb', line 90

def self.append_features(base)
  super
  base.class_eval do
    alias_method :perform_invocation_without_interception, :perform_invocation
    alias_method :perform_invocation, :perform_invocation_with_interception
  end
end

Instance Method Details

#after_invocation(name, args, result) ⇒ Object



128
129
130
# File 'lib/action_service/invocation.rb', line 128

def after_invocation(name, args, result)
  call_interceptors(self.class.after_invocation_interceptors, [name, args, result])
end

#before_invocation(name, args, &block) ⇒ Object



124
125
126
# File 'lib/action_service/invocation.rb', line 124

def before_invocation(name, args, &block)
  call_interceptors(self.class.before_invocation_interceptors, [name, args], &block)
end

#perform_invocation(name, args = nil, options = {}) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/action_service/invocation.rb', line 105

def perform_invocation(name, args=nil, options={})
  unless options[:require_exported] == false
    unless self.respond_to?(name) && self.class.has_export?(name)
      raise InvocationError, "no such exported method '#{name}'"
    end
  end
  args ||= []
  if options[:system_call]
    name, block = options[:system_call]
    if block.respond_to?('call')
      block.call(name, *args)
    else
      self.send(block, *args)
    end
  else
    self.send(name, *args)
  end
end

#perform_invocation_with_interception(name, args = nil, options = {}, &block) ⇒ Object



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

def perform_invocation_with_interception(name, args=nil, options={}, &block)
  return if before_invocation(name, args, &block) == false
  result = perform_invocation_without_interception(name, args, options)
  after_invocation(name, args, result)
  result
end