Module: TeeLogger::Utils

Included in:
TeeLogger
Defined in:
lib/tee_logger/utils.rb

Overview

util

Class Method Summary collapse

Class Method Details

.correct_name?(name) ⇒ true

Returns:

  • (true)


52
53
54
# File 'lib/tee_logger/utils.rb', line 52

def correct_name?(name)
  LOGDEV_NAMES.include?(name) ? true : incorrect_name_error(name)
end

.extract_options(options) ⇒ ParsedOption

Parameters:

  • options (Array)

Returns:



9
10
11
12
13
14
15
16
17
# File 'lib/tee_logger/utils.rb', line 9

def extract_options(options)
  options.each_with_object(ParsedOption.new(nil, 0)) do |val, obj|
    case val
    when Symbol then obj.logdev_name = name_reverse(val)
    when Fixnum then obj.indent_level = val
    else incorrect_option_error(val)
    end
  end
end

.formatting(val) ⇒ String

Returns:

  • (String)


35
36
37
38
39
40
41
# File 'lib/tee_logger/utils.rb', line 35

def formatting(val)
  case val
  when Symbol then ":#{val}"
  when nil    then 'nil'
  else val
  end
end

.incorrect_name_error(name) ⇒ Object



57
58
59
60
# File 'lib/tee_logger/utils.rb', line 57

def incorrect_name_error(name)
  fail IncorrectNameError,
       "logdev_name is :console or :logfile. logdev_name=[:#{name}]"
end

.incorrect_option_error(val) ⇒ Object



63
64
65
66
# File 'lib/tee_logger/utils.rb', line 63

def incorrect_option_error(val)
  fail IncorrectOptionError,
       "option params is Symbol or Fixnum. class=[#{val.class}]"
end

.indentation(progname, block, indent_level) ⇒ Array

Returns:

  • (Array)


23
24
25
26
27
28
29
30
31
# File 'lib/tee_logger/utils.rb', line 23

def indentation(progname, block, indent_level)
  if block.nil?
    progname = "#{' ' * indent_level}#{formatting(progname)}"
  else
    result = block.call
    block  = proc { "#{' ' * indent_level}#{formatting(result)}" }
  end
  [progname, block]
end

.logdev_instance(logdev_name) ⇒ Logger

Returns:

  • (Logger)


70
71
72
# File 'lib/tee_logger/utils.rb', line 70

def logdev_instance(logdev_name)
  instance_variable_get("@#{logdev_name}")
end

.name_reverse(val) ⇒ Symbol

Returns:

  • (Symbol)


45
46
47
48
# File 'lib/tee_logger/utils.rb', line 45

def name_reverse(val)
  correct_name?(val)
  LOGDEV_REVERSE[val]
end