Module: Logue::ColorLog
- Included in:
- Logger
- Defined in:
- lib/logue/colorlog.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/logue/colorlog.rb', line 28
def method_missing meth, *args, &blk
if code = valid_colors[meth]
add_color_method meth.to_s, code + 30
send meth, *args, &blk
else
super
end
end
|
Class Method Details
.color_method_source(color, code) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/logue/colorlog.rb', line 55
def color_method_source color, code
Array.new.tap do |a|
a << 'def ' + color.to_s + '(msg = "", lvl = Logue::Level::DEBUG, classname: nil, &blk)'
a << ' log("\e[' + code.to_s + 'm#{msg}\e[0m", level: lvl, classname: classname, &blk)'
a << 'end'
end.join "\n"
end
|
Instance Method Details
#add_color_method(color, code) ⇒ Object
45
46
47
|
# File 'lib/logue/colorlog.rb', line 45
def add_color_method color, code
instance_eval ColorLog.color_method_source(color, code)
end
|
#methods(all = true) ⇒ Object
41
42
43
|
# File 'lib/logue/colorlog.rb', line 41
def methods all = true
super + valid_colors.keys
end
|
#respond_to?(meth) ⇒ Boolean
37
38
39
|
# File 'lib/logue/colorlog.rb', line 37
def respond_to? meth
valid_colors.include?(meth) || super
end
|
#valid_colors ⇒ Object
49
50
51
52
|
# File 'lib/logue/colorlog.rb', line 49
def valid_colors
Rainbow::Color::Named::NAMES
end
|