Module: Tracing::ActionHandler::Registration

Included in:
Configuration
Defined in:
lib/action_handler/action_handler_registration.rb

Overview

enable registration of action handlers

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#action_handlersObject

Returns the value of attribute action_handlers.



5
6
7
# File 'lib/action_handler/action_handler_registration.rb', line 5

def action_handlers
  @action_handlers
end

Instance Method Details

#action_handler_from_type(type, options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/action_handler/action_handler_registration.rb', line 7

def action_handler_from_type(type, options)      
  if type.kind_of?(Symbol)
    type_sym = type.to_sym
    # use default mappings if no match found
    appender_class = appender_mappings[type_sym] || action_handler_mappings[:default]
    if appender_class
      appender_class.new(options)
    else
      # nil
      raise Exception, "No appender registered for this type: #{type}"
    end
  elsif appender.kind_of? Tracing::OutputTemplate::Trace
    appender
  else
    nil
  end          
end

#create_action_handler(options) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/action_handler/action_handler_registration.rb', line 39

def create_action_handler(options)
  if options.kind_of? Tracing::ActionHandler
    options
  elsif options.kind_of? Hash
    Tracing::ActionHandler.new(options)
  elsif options.kind_of?(Symbol) || options.kind_of?(String)
    type = options.to_sym
    Tracing::Appender.appender_from_type(type, options)
  else
    nil
  end          
end

#create_action_handlers(reg_action_handlers) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/action_handler/action_handler_registration.rb', line 25

def create_action_handlers(reg_action_handlers)
  if reg_action_handlers.kind_of? Array
    reg_action_handlers.flatten!
    new_action_handlers = reg_action_handlers.collect do |f|
      create_action_handler(f)
    end  
    new_action_handlers                  
  elsif reg_action_handlers.kind_of?(Symbol) || reg_action_handlers.kind_of?(Hash)
    create_action_handler(reg_action_handlers)
  else
    reg_action_handlers
  end        
end

#register_action_handlers(reg_action_handlers) ⇒ Object

TODO: add convenience way to register action handlers using symbols!

Raises:

  • (Exception)


53
54
55
56
57
58
# File 'lib/action_handler/action_handler_registration.rb', line 53

def register_action_handlers(reg_action_handlers)
  @action_handlers ||= []
  new_action_handlers = create_action_handlers(reg_action_handlers)
  raise Exception, "No action handlers" if !new_action_handlers
  @action_handlers << new_action_handlers
end