Class: OMF::SFA::AM::RPC::AbstractService

Inherits:
Rack::RPC::Server
  • Object
show all
Includes:
Base::Loggable
Defined in:
lib/omf-sfa/am/am-rpc/abstract_rpc_service.rb

Direct Known Subclasses

AMService

Class Method Summary collapse

Class Method Details

.implement(api) ⇒ Object

This defines a method to declare the service methods and all their parameters.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/omf-sfa/am/am-rpc/abstract_rpc_service.rb', line 23

def self.implement(api)
  @@mappings ||= {}
  api.api_description.each do |m|
    wrapper_name = "_wrapper_#{m.method_name}".to_sym
    self.send(:define_method, wrapper_name) do |*args|
      begin
        self.class.hooks[:before].each do |command| 
          command.call(self) if command.callable?(m.method_name)
        end
        
        out = self.send(m.method_name, *args)
        
        self.class.hooks[:after].each do |command| 
          command.call(self) if command.callable?(m.method_name)
        end
        out
      rescue Exception => ex
        error ex
        debug "Backtrace\n\t#{ex.backtrace.join("\n\t")}"
        raise ex
      end
    end
    #puts "API: map #{m.rpc_name} to #{wrapper_name}"
    @@mappings[m.rpc_name.to_s] = wrapper_name
  end
end

.rpc(mappings = nil) ⇒ Object



50
51
52
53
# File 'lib/omf-sfa/am/am-rpc/abstract_rpc_service.rb', line 50

def self.rpc(mappings = nil)
  raise "Unexpected argument '#{mappings}' for rpc" if mappings
  @@mappings
end