Class: Blabbermouth::Blabber
- Inherits:
-
Object
- Object
- Blabbermouth::Blabber
show all
- Defined in:
- lib/blabbermouth/blabber.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.count(key, total, *args) ⇒ Object
-
.critical(key, e, *args) ⇒ Object
-
.debug(key, e, *args) ⇒ Object
-
.error(key, e, *args) ⇒ Object
-
.flush(*args) ⇒ Object
-
.increment(key, by = 1, *args) ⇒ Object
-
.info(key, msg = nil, *args) ⇒ Object
-
.parse_args(*args) ⇒ Object
-
.time(key, duration = nil, *args, &block) ⇒ Object
-
.warning(key, e, *args) ⇒ Object
Instance Method Summary
collapse
-
#add_bystander(bystander) ⇒ Object
-
#add_bystander!(bystander) ⇒ Object
-
#add_bystanders(*bystdrs) ⇒ Object
-
#blab(meth, key, *args, &block) ⇒ Object
-
#count(key, total, *args) ⇒ Object
-
#critical(key, e, *args) ⇒ Object
-
#debug(key, e = nil, *args) ⇒ Object
-
#error(key, e, *args) ⇒ Object
-
#flush ⇒ Object
-
#increment(key, by = 1, *args) ⇒ Object
-
#info(key, msg = nil, *args) ⇒ Object
-
#method_missing(meth, *args, &block) ⇒ Object
-
#remove_bystander(bystander) ⇒ Object
-
#remove_bystander!(bystander) ⇒ Object
-
#respond_to_missing?(meth, include_private = false) ⇒ Boolean
-
#time(key, duration = nil, *args, &block) ⇒ Object
-
#warning(key, e = nil, *args) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
146
147
148
|
# File 'lib/blabbermouth/blabber.rb', line 146
def method_missing(meth, *args, &block)
blab meth, *args, &block
end
|
Instance Attribute Details
#bystanders ⇒ Object
Returns the value of attribute bystanders.
3
4
5
|
# File 'lib/blabbermouth/blabber.rb', line 3
def bystanders
@bystanders
end
|
#options ⇒ Object
Returns the value of attribute options.
3
4
5
|
# File 'lib/blabbermouth/blabber.rb', line 3
def options
@options
end
|
Class Method Details
.count(key, total, *args) ⇒ Object
43
44
45
46
|
# File 'lib/blabbermouth/blabber.rb', line 43
def count(key, total, *args)
bystanders, opts = parse_args(*args)
new(*bystanders).count(key, total, opts)
end
|
.critical(key, e, *args) ⇒ Object
18
19
20
21
|
# File 'lib/blabbermouth/blabber.rb', line 18
def critical(key, e, *args)
bystanders, opts = parse_args(*args)
new(*bystanders).critical(key, e, opts)
end
|
.debug(key, e, *args) ⇒ Object
28
29
30
31
|
# File 'lib/blabbermouth/blabber.rb', line 28
def debug(key, e, *args)
bystanders, opts = parse_args(*args)
new(*bystanders).debug(key, e, opts)
end
|
.error(key, e, *args) ⇒ Object
13
14
15
16
|
# File 'lib/blabbermouth/blabber.rb', line 13
def error(key, e, *args)
bystanders, opts = parse_args(*args)
new(*bystanders).error(key, e, opts)
end
|
.flush(*args) ⇒ Object
53
54
55
56
|
# File 'lib/blabbermouth/blabber.rb', line 53
def flush(*args)
bystanders, opts = parse_args(*args)
new(*bystanders).flush
end
|
.increment(key, by = 1, *args) ⇒ Object
38
39
40
41
|
# File 'lib/blabbermouth/blabber.rb', line 38
def increment(key, by=1, *args)
bystanders, opts = parse_args(*args)
new(*bystanders).increment(key, by, opts)
end
|
.info(key, msg = nil, *args) ⇒ Object
33
34
35
36
|
# File 'lib/blabbermouth/blabber.rb', line 33
def info(key, msg=nil, *args)
bystanders, opts = parse_args(*args)
new(*bystanders).info(key, msg, opts)
end
|
.parse_args(*args) ⇒ Object
6
7
8
9
10
11
|
# File 'lib/blabbermouth/blabber.rb', line 6
def parse_args(*args)
opts = args.
args = Blabbermouth.configuration.bystanders if args.empty?
bystanders = args + [opts.slice!(:data)]
[bystanders, opts]
end
|
.time(key, duration = nil, *args, &block) ⇒ Object
48
49
50
51
|
# File 'lib/blabbermouth/blabber.rb', line 48
def time(key, duration=nil, *args, &block)
bystanders, opts = parse_args(*args)
new(*bystanders).time(key, duration, opts, &block)
end
|
.warning(key, e, *args) ⇒ Object
23
24
25
26
|
# File 'lib/blabbermouth/blabber.rb', line 23
def warning(key, e, *args)
bystanders, opts = parse_args(*args)
new(*bystanders).warning(key, e, opts)
end
|
Instance Method Details
#add_bystander(bystander) ⇒ Object
67
68
69
70
71
|
# File 'lib/blabbermouth/blabber.rb', line 67
def add_bystander(bystander)
add_bystander! bystander
rescue => e
false
end
|
#add_bystander!(bystander) ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/blabbermouth/blabber.rb', line 59
def add_bystander!(bystander)
@bystanders ||= []
unless bystander_exists?(bystander)
@bystanders << "Blabbermouth::Bystanders::#{bystander.to_s.camelize}".constantize.new(@options[bystander] || {})
end
@bystanders
end
|
#add_bystanders(*bystdrs) ⇒ Object
73
74
75
76
77
|
# File 'lib/blabbermouth/blabber.rb', line 73
def add_bystanders(*bystdrs)
@options.merge!(bystdrs.)
bystdrs.concat(options.keys).uniq
bystdrs.each { |bystander| add_bystander! bystander }
end
|
#blab(meth, key, *args, &block) ⇒ Object
130
131
132
133
134
135
136
137
|
# File 'lib/blabbermouth/blabber.rb', line 130
def blab(meth, key, *args, &block)
opts = args.
bystanders.map do |bystander|
next unless bystander.respond_to?(meth)
bystander_args = args.dup.push(bystander_options(bystander, opts))
bystander.send meth, key, *bystander_args, &block unless Blabbermouth.configuration.gagged == true
end
end
|
#count(key, total, *args) ⇒ Object
114
115
116
|
# File 'lib/blabbermouth/blabber.rb', line 114
def count(key, total, *args)
blab :count, key, total, *args
end
|
#critical(key, e, *args) ⇒ Object
94
95
96
|
# File 'lib/blabbermouth/blabber.rb', line 94
def critical(key, e, *args)
blab :critical, key, e, *args
end
|
#debug(key, e = nil, *args) ⇒ Object
102
103
104
|
# File 'lib/blabbermouth/blabber.rb', line 102
def debug(key, e=nil, *args)
blab :debug, key, e, *args
end
|
#error(key, e, *args) ⇒ Object
90
91
92
|
# File 'lib/blabbermouth/blabber.rb', line 90
def error(key, e, *args)
blab :error, key, e, *args
end
|
#flush ⇒ Object
139
140
141
142
143
144
|
# File 'lib/blabbermouth/blabber.rb', line 139
def flush
bystanders.map do |bystander|
next unless bystander.respond_to?(:flush)
bystander.flush
end
end
|
#increment(key, by = 1, *args) ⇒ Object
110
111
112
|
# File 'lib/blabbermouth/blabber.rb', line 110
def increment(key, by=1, *args)
blab :increment, key, by, *args
end
|
#info(key, msg = nil, *args) ⇒ Object
106
107
108
|
# File 'lib/blabbermouth/blabber.rb', line 106
def info(key, msg=nil, *args)
blab :info, key, msg, *args
end
|
#remove_bystander(bystander) ⇒ Object
84
85
86
87
88
|
# File 'lib/blabbermouth/blabber.rb', line 84
def remove_bystander(bystander)
remove_bystander! bystander
rescue => e
false
end
|
#remove_bystander!(bystander) ⇒ Object
79
80
81
82
|
# File 'lib/blabbermouth/blabber.rb', line 79
def remove_bystander!(bystander)
return if @bystanders.nil?
@bystanders.slice!(bystander_index(bystander), 1)
end
|
#respond_to_missing?(meth, include_private = false) ⇒ Boolean
150
151
152
|
# File 'lib/blabbermouth/blabber.rb', line 150
def respond_to_missing?(meth, include_private=false)
bystanders.any? { |bystander| bystander.respond_to?(meth, include_private) }
end
|
#time(key, duration = nil, *args, &block) ⇒ Object
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/blabbermouth/blabber.rb', line 118
def time(key, duration=nil, *args, &block)
raise "Blabbermouth::Blabber#time requires a duration or block" if duration.nil? && !block_given?
if block_given?
start_time = ::Time.now
yielded = yield
duration = (::Time.now - start_time).to_f
end
blab :time, key, duration, *args
end
|
#warning(key, e = nil, *args) ⇒ Object
98
99
100
|
# File 'lib/blabbermouth/blabber.rb', line 98
def warning(key, e=nil, *args)
blab :warning, key, e, *args
end
|