Module: Tracing::OutputHandler

Included in:
BaseTemplate
Defined in:
lib/output_handler/output_handler.rb

Instance Method Summary collapse

Instance Method Details

#indentationObject

calculate indentation level, based on method stack level (# of nested method calls)



15
16
17
18
19
20
# File 'lib/output_handler/output_handler.rb', line 15

def indentation
  s = ""
  lv = method_stack.empty? ? 0 : method_stack.size-1 
  lv.times { s << (" " * space_count) }
  s
end

#method_stackObject

TODO: refactor (duplicate of appender method)



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

def method_stack
  @method_stack ||= []
end

#output(template, context) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/output_handler/output_handler.rb', line 22

def output(template, context)
  # get spaces to indent each line
  spaces = indentation

  # modify template, inserting indentation
  lines = template.split("\n")
  lines.map!{|line| spaces + line + "\n"}
  template = lines.join

  # send modified template to output handler with context
  output_handler(template, context)
end

#output_handler(template, context) ⇒ Object

default output action: put string to STDOUT override this to customize trace handling



37
38
39
40
41
42
43
44
45
# File 'lib/output_handler/output_handler.rb', line 37

def output_handler(template, context)
  # create new erb template
  erb_template = ERB.new template
  
  # evaluate erb template for output using context
  str_res = erb_template.result(binding)
  # send final output to action handlers for further processing...
  # action_handlers(str_res, context)
end

#space_countObject

override to increase # of spaces for each indenation level!



10
11
12
# File 'lib/output_handler/output_handler.rb', line 10

def space_count
  1
end