Module: CollinsNotify::ConfigurationMixin
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
Handles magic getters/setters
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/collins_notify/configuration_mixin.rb', line 30
def method_missing m, *args, &block
kname = m.to_s.gsub(/=$/, '')
is_configurable = configurable.key?(kname.to_sym)
is_assignment = is_configurable && m.to_s[-1].eql?('=') && args.size > 0
if is_configurable && !is_assignment then
get_cfg_var "@#{kname}".to_sym
elsif is_assignment then
formatter_name = "format_#{kname}".to_sym
if args.size == 1 then
value = args.first
else
value = args
end
if respond_to?(formatter_name, true) then
value = send(formatter_name, value)
end
validator_name = "valid_#{kname}?".to_sym
unless respond_to?(validator_name, true) then
raise NotImplementedError.new "ConfigurationMixin##{validator_name} must be implemented"
end
if send(validator_name, value) then
set_cfg_var "@#{kname}".to_sym, value
else
raise CollinsNotify::ConfigurationError.new "#{kname} #{value.inspect} is not valid"
end
else
super
end
end
|
Instance Method Details
#config ⇒ Object
5
6
7
|
# File 'lib/collins_notify/configuration_mixin.rb', line 5
def config
raise NotImplementedError.new "ConfigurationMixin#config must be implemented"
end
|
#debug? ⇒ Boolean
17
|
# File 'lib/collins_notify/configuration_mixin.rb', line 17
def debug?; severity <= Logger::DEBUG; end
|
#error? ⇒ Boolean
14
|
# File 'lib/collins_notify/configuration_mixin.rb', line 14
def error?; severity <= Logger::ERROR; end
|
#fatal? ⇒ Boolean
13
|
# File 'lib/collins_notify/configuration_mixin.rb', line 13
def fatal?; severity <= Logger::FATAL; end
|
#info? ⇒ Boolean
16
|
# File 'lib/collins_notify/configuration_mixin.rb', line 16
def info?; severity <= Logger::INFO; end
|
#sevname ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/collins_notify/configuration_mixin.rb', line 19
def sevname
if trace? then
"TRACE"
else
Logger::SEV_LABEL[severity]
end
end
|
#test? ⇒ Boolean
27
|
# File 'lib/collins_notify/configuration_mixin.rb', line 27
def test?; (config.test == true); end
|
#to_hash ⇒ Object
65
66
67
68
69
|
# File 'lib/collins_notify/configuration_mixin.rb', line 65
def to_hash
configurable.inject({}) do |ret, (k,v)|
ret.update(k => get_cfg_var("@#{k.to_s}".to_sym))
end
end
|
#trace? ⇒ Boolean
18
|
# File 'lib/collins_notify/configuration_mixin.rb', line 18
def trace?; severity <= Logger::TRACE; end
|
#valid? ⇒ Boolean
9
10
11
|
# File 'lib/collins_notify/configuration_mixin.rb', line 9
def valid?
raise NotImplementedError.new "ConfigurationMixin#valid? must be implemented"
end
|
#warn? ⇒ Boolean
15
|
# File 'lib/collins_notify/configuration_mixin.rb', line 15
def warn?; severity <= Logger::WARN; end
|