Class: Carioca::Services::ProxyDebug

Inherits:
Object
  • Object
show all
Defined in:
lib/carioca/services/debug.rb

Overview

Service Debug of Carioca Proxy Class Debug for devs

Instance Method Summary collapse

Constructor Details

#initialize(_options) ⇒ ProxyDebug

ProxyDebug service constructor (has a class proxy => so a service proxy)

Parameters:

  • _options (Hash)

    the params

Options Hash (_options):

  • :service (String)

    the name of the service you want to proxyfying

  • :params (Hash)

    the params of the proxyfied service



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/carioca/services/debug.rb', line 31

def initialize(_options)
  options = Methodic.get_options(_options)
  options.specify_classes_of :service => String
  options.specify_presence_of([:service])
  options.validate!
  if options[:params] then
    @obj = Registry.init.start_service :name  => options[:service], :params => options[:params]
  else
    @obj = Registry.init.start_service :name  => options[:service]
  end
  @log  = Registry.init.get_service :name => 'logger'
  @mapped_service = options[:service]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(methodname, *args, &block) ⇒ Object

method_missing overload to make the class proxy efficient



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/carioca/services/debug.rb', line 46

def method_missing(methodname, *args,&block)
  @log.debug("ProxyDebug") { "BEGIN CALL for mapped service #{@mapped_service} "}
  @log.debug("ProxyDebug") { "called: #{methodname} " }
  @log.debug("ProxyDebug") { "args : #{args.join " "}" }
  if block_given? then
    @log.debug("ProxyDebug") { "block given" }
    a = @obj.send(methodname, *args,&block)
  else
    a = @obj.send(methodname, *args)
  end
  @log.debug("ProxyDebug") { "=> returned: #{a} " }
  @log.debug("ProxyDebug") { 'END CALL' }
  return a
end