blabbermouth 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/blabbermouth.rb +53 -0
- data/lib/blabbermouth/blabber.rb +126 -0
- data/lib/blabbermouth/configuration.rb +66 -0
- data/lib/blabbermouth/exceptions.rb +16 -0
- data/lib/blabbermouth/gawkers.rb +7 -0
- data/lib/blabbermouth/gawkers/base.rb +39 -0
- data/lib/blabbermouth/gawkers/stdout.rb +43 -0
- data/lib/blabbermouth/version.rb +1 -1
- data/spec/blabbermouth/blabber_spec.rb +124 -0
- data/spec/blabbermouth/gawkers/base_spec.rb +33 -0
- data/spec/blabbermouth/gawkers/stdout_spec.rb +53 -0
- data/spec/blabbermouth_spec.rb +48 -0
- data/spec/spec_helper.rb +0 -18
- data/spec/support/capture_stdout.rb +1 -1
- data/spec/support/gawker.rb +46 -0
- metadata +20 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fb2f9e6c18a243b3d51744b2a5983ce7cc79535
|
4
|
+
data.tar.gz: d018f5297e202f6dc724ac472c029fec2ad7fb1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d345dd1cf0caefdb0ae661a5bdc94e0d911c45655ead5ac11b100b7bc245f02704bccb9d0e3542e99385686c7e6b1823ad3b62402709e9833dc4d14a7bafe878
|
7
|
+
data.tar.gz: 1f672699d3d0f950c5938e24471b9f3d97bae4a19ad32c1ce2c1332c58e100ceaf1139e3705be01e72a2b276a109b05c190c52e0075518867f746e31ee46b0bf
|
data/lib/blabbermouth.rb
CHANGED
@@ -1,2 +1,55 @@
|
|
1
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
2
|
+
require 'active_support/core_ext/array/extract_options'
|
3
|
+
require 'active_support/core_ext/string'
|
4
|
+
require 'blabbermouth/version'
|
5
|
+
require 'blabbermouth/configuration'
|
6
|
+
require 'blabbermouth/gawkers'
|
7
|
+
require 'blabbermouth/blabber'
|
8
|
+
|
1
9
|
module Blabbermouth
|
10
|
+
mattr_reader :configuration
|
11
|
+
@@configuration = Blabbermouth::Configuration.new
|
12
|
+
|
13
|
+
def self.configure(&block)
|
14
|
+
@@configuration.configure &block
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.blabber(*gawkers)
|
18
|
+
Blabbermouth::Blabber.new *gawkers
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.new(*gawkers)
|
22
|
+
blabber *gawkers
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.error(key, e, *args)
|
26
|
+
opts = args.extract_options!
|
27
|
+
gawkers = args.concat([opts.slice!(:data)])
|
28
|
+
blabber(*gawkers).error(key, e, opts)
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.info(key, msg=nil, *args)
|
32
|
+
opts = args.extract_options!
|
33
|
+
gawkers = args.concat([opts.slice!(:data)])
|
34
|
+
blabber(*gawkers).info(key, msg, opts)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.increment(key, by=1, *args)
|
38
|
+
opts = args.extract_options!
|
39
|
+
gawkers = args.concat([opts.slice!(:data)])
|
40
|
+
blabber(*gawkers).increment(key, by, opts)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.count(key, total, *args)
|
44
|
+
opts = args.extract_options!
|
45
|
+
gawkers = args.concat([opts.slice!(:data)])
|
46
|
+
blabber(*gawkers).count(key, total, opts)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.time(key, duration=nil, *args, &block)
|
50
|
+
raise "Blabbermouth.time requires a duration or block" if duration.nil? && !block_given?
|
51
|
+
opts = args.extract_options!
|
52
|
+
gawkers = args.concat([opts.slice!(:data)])
|
53
|
+
blabber(*gawkers).time(key, duration, opts, &block)
|
54
|
+
end
|
2
55
|
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
module Blabbermouth
|
2
|
+
class Blabber
|
3
|
+
attr_reader :gawkers, :options
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def error(key, e, *args)
|
7
|
+
opts = args.extract_options!
|
8
|
+
gawkers = args.concat([opts.slice!(:data)])
|
9
|
+
new(*gawkers).error(key, e, opts)
|
10
|
+
end
|
11
|
+
|
12
|
+
def info(key, msg=nil, *args)
|
13
|
+
opts = args.extract_options!
|
14
|
+
gawkers = args.concat([opts.slice!(:data)])
|
15
|
+
new(*gawkers).info(key, msg, opts)
|
16
|
+
end
|
17
|
+
|
18
|
+
def increment(key, by=1, *args)
|
19
|
+
opts = args.extract_options!
|
20
|
+
gawkers = args.concat([opts.slice!(:data)])
|
21
|
+
new(*gawkers).increment(key, by, opts)
|
22
|
+
end
|
23
|
+
|
24
|
+
def count(key, total, *args)
|
25
|
+
opts = args.extract_options!
|
26
|
+
gawkers = args.concat([opts.slice!(:data)])
|
27
|
+
new(*gawkers).count(key, total, opts)
|
28
|
+
end
|
29
|
+
|
30
|
+
def time(key, duration=nil, *args, &block)
|
31
|
+
opts = args.extract_options!
|
32
|
+
gawkers = args.concat([opts.slice!(:data)])
|
33
|
+
new(*gawkers).time(key, duration, opts, &block)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def add_gawker!(gawker)
|
38
|
+
@gawkers ||= []
|
39
|
+
unless gawker_exists?(gawker)
|
40
|
+
@gawkers << "Blabbermouth::Gawkers::#{gawker.to_s.camelize}".constantize.new
|
41
|
+
end
|
42
|
+
@gawkers
|
43
|
+
end
|
44
|
+
|
45
|
+
def add_gawker(gawker)
|
46
|
+
add_gawker! gawker
|
47
|
+
rescue => e
|
48
|
+
false
|
49
|
+
end
|
50
|
+
|
51
|
+
def remove_gawker!(gawker)
|
52
|
+
return if @gawkers.nil?
|
53
|
+
@gawkers.slice!(gawker_index(gawker), 1)
|
54
|
+
end
|
55
|
+
|
56
|
+
def remove_gawker(gawker)
|
57
|
+
remove_gawker! gawker
|
58
|
+
rescue => e
|
59
|
+
false
|
60
|
+
end
|
61
|
+
|
62
|
+
def error(key, e, *args)
|
63
|
+
opts = args.extract_options!
|
64
|
+
gawkers.map { |gawker| gawker.error key, e, *args.concat([gawker_options(gawker).merge(opts)]) }
|
65
|
+
end
|
66
|
+
|
67
|
+
def info(key, msg=nil, *args)
|
68
|
+
opts = args.extract_options!
|
69
|
+
gawkers.map { |gawker| gawker.info key, msg, *args.concat([gawker_options(gawker).merge(opts)]) }
|
70
|
+
end
|
71
|
+
|
72
|
+
def increment(key, by=1, *args)
|
73
|
+
opts = args.extract_options!
|
74
|
+
gawkers.map { |gawker| gawker.increment key, by, *args.concat([gawker_options(gawker).merge(opts)]) }
|
75
|
+
end
|
76
|
+
|
77
|
+
def count(key, total, *args)
|
78
|
+
opts = args.extract_options!
|
79
|
+
gawkers.map { |gawker| gawker.count key, total, *args.concat([gawker_options(gawker).merge(opts)]) }
|
80
|
+
end
|
81
|
+
|
82
|
+
def time(key, duration=nil, *args, &block)
|
83
|
+
raise "Blabbermouth::Blabber.time requires a duration or block" if duration.nil? && !block_given?
|
84
|
+
opts = args.extract_options!
|
85
|
+
|
86
|
+
if block_given?
|
87
|
+
start_time = ::Time.now
|
88
|
+
yielded = yield
|
89
|
+
duration = (::Time.now - start_time).to_f
|
90
|
+
end
|
91
|
+
|
92
|
+
gawkers.map { |gawker| gawker.time key, duration, *args.concat([gawker_options(gawker).merge(opts)]) }
|
93
|
+
end
|
94
|
+
|
95
|
+
def method_missing(meth, *args, &block)
|
96
|
+
gawkers.map do |gawker|
|
97
|
+
next unless gawker.respond_to?(meth)
|
98
|
+
gawker.send(meth, *args, &block)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def respond_to_missing?(meth, include_private=false)
|
103
|
+
gawkers.any? { |gawker| gawker.respond_to?(meth, include_private) }
|
104
|
+
end
|
105
|
+
|
106
|
+
protected
|
107
|
+
|
108
|
+
def initialize(*gawks)
|
109
|
+
@options = gawks.extract_options!
|
110
|
+
gawks.concat(options.keys)
|
111
|
+
gawks.each { |gawker| add_gawker gawker }
|
112
|
+
end
|
113
|
+
|
114
|
+
def gawker_options(gawker)
|
115
|
+
@options[gawker.class.name.demodulize.underscore.to_sym] || {}
|
116
|
+
end
|
117
|
+
|
118
|
+
def gawker_index(gawker)
|
119
|
+
@gawkers.index { |gawk| gawk.class.name.demodulize.underscore == gawker.to_s }
|
120
|
+
end
|
121
|
+
|
122
|
+
def gawker_exists?(gawker)
|
123
|
+
!gawker_index(gawker).nil?
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Blabbermouth
|
2
|
+
class Configuration
|
3
|
+
DEFAULT_CONFIGURATION_OPTIONS = {
|
4
|
+
}
|
5
|
+
|
6
|
+
attr_reader *DEFAULT_CONFIGURATION_OPTIONS.keys
|
7
|
+
|
8
|
+
DEFAULT_CONFIGURATION_OPTIONS.keys.each do |key|
|
9
|
+
define_method "#{key.to_s}=" do |val|
|
10
|
+
@changed[key] = [send(key), val]
|
11
|
+
instance_variable_set "@#{key.to_s}", val
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def changed
|
16
|
+
@changed = {}
|
17
|
+
to_hash.each { |key,val| @changed[key] = [@saved_state[key], val] if @saved_state[key] != val }
|
18
|
+
@changed
|
19
|
+
end
|
20
|
+
|
21
|
+
def changed?(key)
|
22
|
+
changed.has_key?(key)
|
23
|
+
end
|
24
|
+
|
25
|
+
def configure(args={}, &block)
|
26
|
+
save_state
|
27
|
+
configure_with_args args
|
28
|
+
configure_with_block &block
|
29
|
+
self
|
30
|
+
end
|
31
|
+
|
32
|
+
def configure_with_args(args)
|
33
|
+
args.select { |k,v| DEFAULT_CONFIGURATION_OPTIONS.keys.include?(k) }.each do |key,val|
|
34
|
+
instance_variable_set "@#{key.to_s}", val
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def configure_with_block(&block)
|
39
|
+
self.instance_eval(&block) if block_given?
|
40
|
+
end
|
41
|
+
|
42
|
+
def save_state
|
43
|
+
@saved_state = clone.to_hash
|
44
|
+
@changed = {}
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def to_hash
|
49
|
+
h = {}
|
50
|
+
DEFAULT_CONFIGURATION_OPTIONS.keys.each do |key|
|
51
|
+
h[key] = instance_variable_get "@#{key.to_s}"
|
52
|
+
end
|
53
|
+
h
|
54
|
+
end
|
55
|
+
alias_method :to_h, :to_hash
|
56
|
+
|
57
|
+
protected
|
58
|
+
|
59
|
+
def initialize
|
60
|
+
DEFAULT_CONFIGURATION_OPTIONS.each do |key,val|
|
61
|
+
instance_variable_set "@#{key.to_s}", val
|
62
|
+
end
|
63
|
+
save_state
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Blabbermouth
|
2
|
+
class Error < ::StandardError
|
3
|
+
def initialize(key, e)
|
4
|
+
super("#{key}: #{e.message}")
|
5
|
+
set_backtrace e.backtrace
|
6
|
+
end
|
7
|
+
end
|
8
|
+
class Info < ::StandardError
|
9
|
+
def initialize(key, msg)
|
10
|
+
super("#{key}: #{msg}")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
class Increment < Info; end
|
14
|
+
class Count < Info; end
|
15
|
+
class Time < Info; end
|
16
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Blabbermouth
|
2
|
+
module Gawkers
|
3
|
+
class Base
|
4
|
+
def error(key, e, *args)
|
5
|
+
raise NotImplementedError, "#{self.class.name}##{__method__} has not been implemented"
|
6
|
+
end
|
7
|
+
|
8
|
+
def info(key, msg=nil, *args)
|
9
|
+
raise NotImplementedError, "#{self.class.name}##{__method__} has not been implemented"
|
10
|
+
end
|
11
|
+
|
12
|
+
def increment(key, by=1, *args)
|
13
|
+
raise NotImplementedError, "#{self.class.name}##{__method__} has not been implemented"
|
14
|
+
end
|
15
|
+
|
16
|
+
def count(key, total, *args)
|
17
|
+
raise NotImplementedError, "#{self.class.name}##{__method__} has not been implemented"
|
18
|
+
end
|
19
|
+
|
20
|
+
def time(key, duration=nil, *args)
|
21
|
+
raise NotImplementedError, "#{self.class.name}##{__method__} has not been implemented"
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
# data, opts, args = parse_args(*args)
|
27
|
+
# parse_args(*args) { |data, opts, args| ... }
|
28
|
+
def parse_args(*args, &block)
|
29
|
+
opts = args.extract_options!
|
30
|
+
data = opts.delete(:data) || {}
|
31
|
+
if block_given?
|
32
|
+
yield data, opts, args
|
33
|
+
else
|
34
|
+
[data, opts, args]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Blabbermouth
|
2
|
+
module Gawkers
|
3
|
+
class Stdout < Base
|
4
|
+
def error(key, e, *args)
|
5
|
+
data, opts, args = parse_args(*args)
|
6
|
+
puts :error, key, e.message, data
|
7
|
+
end
|
8
|
+
|
9
|
+
def info(key, msg=nil, *args)
|
10
|
+
data, opts, args = parse_args(*args)
|
11
|
+
puts :info, key, msg, data
|
12
|
+
end
|
13
|
+
|
14
|
+
def increment(key, by=1, *args)
|
15
|
+
data, opts, args = parse_args(*args)
|
16
|
+
puts :increment, key, by, data
|
17
|
+
end
|
18
|
+
|
19
|
+
def count(key, total, *args)
|
20
|
+
data, opts, args = parse_args(*args)
|
21
|
+
puts :count, key, total, data
|
22
|
+
end
|
23
|
+
|
24
|
+
def time(key, value=nil, *args)
|
25
|
+
data, opts, args = parse_args(*args)
|
26
|
+
puts :time, key, value, data
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def puts(event, key, msg, data={})
|
32
|
+
$stdout.puts log_message(event, key, msg, data)
|
33
|
+
end
|
34
|
+
|
35
|
+
def log_message(event, key, msg, data={})
|
36
|
+
message = "[#{::Time.now.strftime('%Y/%m/%d %H:%M:%S %Z')}] Blabbermouth.#{event.to_s}: #{key.to_s}"
|
37
|
+
message += ": #{msg.to_s}" unless msg.to_s.blank?
|
38
|
+
message += " #{data.to_s}"
|
39
|
+
message
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/blabbermouth/version.rb
CHANGED
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Blabbermouth::Blabber do
|
4
|
+
describe '#add_gawker!' do
|
5
|
+
context 'when the gawker does not exist' do
|
6
|
+
it 'adds a gawker to the list of gawkers' do
|
7
|
+
subject.add_gawker!(:rails)
|
8
|
+
expect(subject.gawkers.count).to eql(1)
|
9
|
+
expect(subject.gawkers.first).to be_an_instance_of(Blabbermouth::Gawkers::Rails)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#remove_gawker!' do
|
15
|
+
context 'when the gawker exists' do
|
16
|
+
it 'removes a gawker from the list of gawkers' do
|
17
|
+
subject.add_gawker!(:rails)
|
18
|
+
expect(subject.gawkers.count).to eql(1)
|
19
|
+
subject.remove_gawker!(:rails)
|
20
|
+
expect(subject.gawkers.count).to eql(0)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#error' do
|
26
|
+
it 'blabs to any added gawkers' do
|
27
|
+
subject.add_gawker!(:test)
|
28
|
+
subject.add_gawker!(:rails)
|
29
|
+
subject.error('key', StandardError.new)
|
30
|
+
expect(Blabbermouth::Gawkers::Test.logged?(:error, 'key', StandardError.new.message)).to be_true
|
31
|
+
expect(Rails.logger.errors).to include(Blabbermouth::Gawkers::Rails.new.send(:log_message, :error, 'key', StandardError.new))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#info' do
|
36
|
+
it 'blabs to any added gawkers' do
|
37
|
+
subject.add_gawker!(:test)
|
38
|
+
subject.add_gawker!(:rails)
|
39
|
+
subject.info('key', 'test')
|
40
|
+
expect(Blabbermouth::Gawkers::Test.logged?(:info, 'key', 'test')).to be_true
|
41
|
+
expect(Rails.logger.infos).to include(Blabbermouth::Gawkers::Rails.new.send(:log_message, :info, 'key', 'test'))
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#increment' do
|
46
|
+
it 'blabs to any added gawkers' do
|
47
|
+
subject.add_gawker!(:test)
|
48
|
+
subject.add_gawker!(:rails)
|
49
|
+
subject.increment('key', 1)
|
50
|
+
expect(Blabbermouth::Gawkers::Test.logged?(:increment, 'key', 1)).to be_true
|
51
|
+
expect(Rails.logger.infos).to include(Blabbermouth::Gawkers::Rails.new.send(:log_message, :increment, 'key', 1))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#count' do
|
56
|
+
it 'blabs to any added gawkers' do
|
57
|
+
subject.add_gawker!(:test)
|
58
|
+
subject.add_gawker!(:rails)
|
59
|
+
subject.count('key', 1)
|
60
|
+
expect(Blabbermouth::Gawkers::Test.logged?(:count, 'key', 1)).to be_true
|
61
|
+
expect(Rails.logger.infos).to include(Blabbermouth::Gawkers::Rails.new.send(:log_message, :count, 'key', 1))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#time' do
|
66
|
+
it 'blabs to any added gawkers' do
|
67
|
+
subject.add_gawker!(:test)
|
68
|
+
subject.add_gawker!(:rails)
|
69
|
+
subject.time('key', 1)
|
70
|
+
expect(Blabbermouth::Gawkers::Test.logged?(:time, 'key', 1)).to be_true
|
71
|
+
expect(Rails.logger.infos).to include(Blabbermouth::Gawkers::Rails.new.send(:log_message, :time, 'key', 1))
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe '#method_missing' do
|
76
|
+
context 'when added gawkers respond to the requested method' do
|
77
|
+
it 'passes method calls through to added gawkers' do
|
78
|
+
subject.add_gawker!(:test)
|
79
|
+
subject.test('key', 'test')
|
80
|
+
expect(Blabbermouth::Gawkers::Test.logged?(:test, 'key', 'test')).to be_true
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '.error' do
|
86
|
+
it 'blabs to any provided gawkers' do
|
87
|
+
Blabbermouth::Blabber.error('key', StandardError.new, :test, :rails)
|
88
|
+
expect(Blabbermouth::Gawkers::Test.logged?(:error, 'key', StandardError.new.message)).to be_true
|
89
|
+
expect(Rails.logger.errors).to include(Blabbermouth::Gawkers::Rails.new.send(:log_message, :error, 'key', StandardError.new))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '.info' do
|
94
|
+
it 'blabs to any provided gawkers' do
|
95
|
+
Blabbermouth::Blabber.info('key', 'test', :test, :rails)
|
96
|
+
expect(Blabbermouth::Gawkers::Test.logged?(:info, 'key', 'test')).to be_true
|
97
|
+
expect(Rails.logger.infos).to include(Blabbermouth::Gawkers::Rails.new.send(:log_message, :info, 'key', 'test'))
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '.increment' do
|
102
|
+
it 'blabs to any provided gawkers' do
|
103
|
+
Blabbermouth::Blabber.increment('key', 1, :test, :rails)
|
104
|
+
expect(Blabbermouth::Gawkers::Test.logged?(:increment, 'key', 1)).to be_true
|
105
|
+
expect(Rails.logger.infos).to include(Blabbermouth::Gawkers::Rails.new.send(:log_message, :increment, 'key', 1))
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '.count' do
|
110
|
+
it 'blabs to any provided gawkers' do
|
111
|
+
Blabbermouth::Blabber.count('key', 1, :test, :rails)
|
112
|
+
expect(Blabbermouth::Gawkers::Test.logged?(:count, 'key', 1)).to be_true
|
113
|
+
expect(Rails.logger.infos).to include(Blabbermouth::Gawkers::Rails.new.send(:log_message, :count, 'key', 1))
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '.time' do
|
118
|
+
it 'blabs to any provided gawkers' do
|
119
|
+
Blabbermouth::Blabber.time('key', 1, :test, :rails)
|
120
|
+
expect(Blabbermouth::Gawkers::Test.logged?(:time, 'key', 1)).to be_true
|
121
|
+
expect(Rails.logger.infos).to include(Blabbermouth::Gawkers::Rails.new.send(:log_message, :time, 'key', 1))
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Blabbermouth::Gawkers::Base do
|
4
|
+
describe '#error' do
|
5
|
+
it 'raises NotImplementedError' do
|
6
|
+
expect { subject.error('key', StandardError.new) }.to raise_exception(NotImplementedError)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#info' do
|
11
|
+
it 'raises NotImplementedError' do
|
12
|
+
expect { subject.info('key', 'test') }.to raise_exception(NotImplementedError)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#increment' do
|
17
|
+
it 'raises NotImplementedError' do
|
18
|
+
expect { subject.increment('key', 1) }.to raise_exception(NotImplementedError)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#count' do
|
23
|
+
it 'raises NotImplementedError' do
|
24
|
+
expect { subject.count('key', 1) }.to raise_exception(NotImplementedError)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#time' do
|
29
|
+
it 'raises NotImplementedError' do
|
30
|
+
expect { subject.time('key', 1) }.to raise_exception(NotImplementedError)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Blabbermouth::Gawkers::Stdout do
|
4
|
+
describe '#error' do
|
5
|
+
it 'outputs to STDOUT' do
|
6
|
+
expect(capture_stdout { subject.error('key', StandardError.new) }).to eql(subject.send(:log_message, :error, 'key', StandardError.new))
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'accepts a data hash' do
|
10
|
+
expect(capture_stdout { subject.error('test.error', StandardError.new, data: {test: :argument}) }).to eql(subject.send(:log_message, :error, 'test.error', StandardError.new, {test: :argument}))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#info' do
|
15
|
+
it 'outputs to STDOUT' do
|
16
|
+
expect(capture_stdout { subject.info('key', 'test') }).to eql(subject.send(:log_message, :info, 'key', 'test'))
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'accepts a data hash' do
|
20
|
+
expect(capture_stdout { subject.info('test.info', 'test data', data: {test: :argument}) }).to eql(subject.send(:log_message, :info, 'test.info', 'test data', {test: :argument}))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#increment' do
|
25
|
+
it 'outputs to STDOUT' do
|
26
|
+
expect(capture_stdout { subject.increment('key', 1) }).to eql(subject.send(:log_message, :increment, 'key', 1))
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'accepts a data hash' do
|
30
|
+
expect(capture_stdout { subject.increment('test.increment', 1, data: {test: :argument}) }).to eql(subject.send(:log_message, :increment, 'test.increment', 1, {test: :argument}))
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#count' do
|
35
|
+
it 'outputs to STDOUT' do
|
36
|
+
expect(capture_stdout { subject.count('key', 1) }).to eql(subject.send(:log_message, :count, 'key', 1))
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'accepts a data hash' do
|
40
|
+
expect(capture_stdout { subject.count('test.count', 1, data: {test: :argument}) }).to eql(subject.send(:log_message, :count, 'test.count', 1, {test: :argument}))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#time' do
|
45
|
+
it 'outputs to STDOUT' do
|
46
|
+
expect(capture_stdout { subject.time('key', 1) }).to eql(subject.send(:log_message, :time, 'key', 1))
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'accepts a data hash' do
|
50
|
+
expect(capture_stdout { subject.time('test.time', 1, data: {test: :argument}) }).to eql(subject.send(:log_message, :time, 'test.time', 1, {test: :argument}))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Blabbermouth do
|
4
|
+
describe '#error' do
|
5
|
+
it 'blabs to any provided gawkers' do
|
6
|
+
subject.error('key', StandardError.new, :rollbar, :rails)
|
7
|
+
error = ::Rollbar.errors.last
|
8
|
+
expect(error[0]).to be_an_instance_of(Blabbermouth::Error)
|
9
|
+
expect(Rails.logger.errors).to include(Blabbermouth::Gawkers::Rails.new.send(:log_message, :error, 'key', StandardError.new))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#info' do
|
14
|
+
it 'blabs to any provided gawkers' do
|
15
|
+
subject.info('key', 'test', :rollbar, :rails)
|
16
|
+
info = ::Rollbar.infos.last
|
17
|
+
expect(info[0]).to be_an_instance_of(Blabbermouth::Info)
|
18
|
+
expect(Rails.logger.infos).to include(Blabbermouth::Gawkers::Rails.new.send(:log_message, :info, 'key', 'test'))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#increment' do
|
23
|
+
it 'blabs to any provided gawkers' do
|
24
|
+
subject.increment('key', 1, :rollbar, :rails)
|
25
|
+
info = ::Rollbar.infos.last
|
26
|
+
expect(info[0]).to be_an_instance_of(Blabbermouth::Increment)
|
27
|
+
expect(Rails.logger.infos).to include(Blabbermouth::Gawkers::Rails.new.send(:log_message, :increment, 'key', 1))
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#count' do
|
32
|
+
it 'blabs to any provided gawkers' do
|
33
|
+
subject.count('key', 1, :rollbar, :rails)
|
34
|
+
info = ::Rollbar.infos.last
|
35
|
+
expect(info[0]).to be_an_instance_of(Blabbermouth::Count)
|
36
|
+
expect(Rails.logger.infos).to include(Blabbermouth::Gawkers::Rails.new.send(:log_message, :count, 'key', 1))
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#time' do
|
41
|
+
it 'blabs to any provided gawkers' do
|
42
|
+
subject.time('key', 1, :rollbar, :rails)
|
43
|
+
info = ::Rollbar.infos.last
|
44
|
+
expect(info[0]).to be_an_instance_of(Blabbermouth::Time)
|
45
|
+
expect(Rails.logger.infos).to include(Blabbermouth::Gawkers::Rails.new.send(:log_message, :time, 'key', 1))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
require 'active_record'
|
2
1
|
require 'blabbermouth'
|
3
|
-
require 'factory_girl'
|
4
|
-
require 'faker'
|
5
2
|
require 'rspec'
|
6
3
|
|
7
4
|
Dir[File.join(File.dirname(__FILE__), '..', "spec/support/**/*.rb")].each { |f| require f }
|
8
|
-
Dir[File.join(File.dirname(__FILE__), '..', "spec/factories/**/*.rb")].each { |f| require f }
|
9
5
|
|
10
6
|
RSpec.configure do |config|
|
11
7
|
#config.before(:suite) do
|
@@ -14,20 +10,6 @@ RSpec.configure do |config|
|
|
14
10
|
# load 'support/models.rb'
|
15
11
|
#end
|
16
12
|
|
17
|
-
# Using Factory Girl instead of fixtures
|
18
|
-
config.include FactoryGirl::Syntax::Methods
|
19
|
-
# Lint your factories before running the suite to find any errors up front
|
20
|
-
config.before(:suite) do
|
21
|
-
ActiveRecord::Base.transaction do
|
22
|
-
begin
|
23
|
-
FactoryGirl.lint
|
24
|
-
rescue FactoryGirl::InvalidFactoryError => e
|
25
|
-
puts e.message
|
26
|
-
end
|
27
|
-
raise ActiveRecord::Rollback
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
13
|
# rspec-expectations config goes here. You can use an alternate
|
32
14
|
# assertion/expectation library such as wrong or the stdlib/minitest
|
33
15
|
# assertions if you prefer.
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Blabbermouth
|
2
|
+
module Gawkers
|
3
|
+
class Test < Base
|
4
|
+
EVENTS = []
|
5
|
+
attr_reader :events
|
6
|
+
|
7
|
+
def self.logged?(event, key, msg)
|
8
|
+
EVENTS.any? { |e| e == [event, key, msg] }
|
9
|
+
end
|
10
|
+
|
11
|
+
def logged?(event, key, msg)
|
12
|
+
self.class.logged? event, key, msg
|
13
|
+
end
|
14
|
+
|
15
|
+
def error(key, e, *args, data: {})
|
16
|
+
log :error, key, e.message, data
|
17
|
+
end
|
18
|
+
|
19
|
+
def info(key, msg=nil, *args, data: {})
|
20
|
+
log :info, key, msg, data
|
21
|
+
end
|
22
|
+
|
23
|
+
def increment(key, by, *args, data: {})
|
24
|
+
log :increment, key, by, data
|
25
|
+
end
|
26
|
+
|
27
|
+
def count(key, total, *args, data: {})
|
28
|
+
log :count, key, total, data
|
29
|
+
end
|
30
|
+
|
31
|
+
def time(key, value=nil, *args, data: {})
|
32
|
+
log :time, key, value, data
|
33
|
+
end
|
34
|
+
|
35
|
+
def test(key, msg=nil, *args, data: {})
|
36
|
+
log :test, key, msg, data
|
37
|
+
end
|
38
|
+
|
39
|
+
protected
|
40
|
+
|
41
|
+
def log(event, key, msg, data={})
|
42
|
+
EVENTS << [event, key, msg]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,37 +1,23 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blabbermouth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rebec
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
|
-
type: :
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: sqlite3
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
20
|
+
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
@@ -66,34 +52,6 @@ dependencies:
|
|
66
52
|
- - ">="
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: factory_girl
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: faker
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
55
|
description: Flexible instrumentation/reporting library for pushing info, errors,
|
98
56
|
counts, timing, etc. to various datastores like Librato, Rollbar, Rails logs or
|
99
57
|
custom ActiveRecord models
|
@@ -104,9 +62,20 @@ extensions: []
|
|
104
62
|
extra_rdoc_files: []
|
105
63
|
files:
|
106
64
|
- lib/blabbermouth.rb
|
65
|
+
- lib/blabbermouth/blabber.rb
|
66
|
+
- lib/blabbermouth/configuration.rb
|
67
|
+
- lib/blabbermouth/exceptions.rb
|
68
|
+
- lib/blabbermouth/gawkers.rb
|
69
|
+
- lib/blabbermouth/gawkers/base.rb
|
70
|
+
- lib/blabbermouth/gawkers/stdout.rb
|
107
71
|
- lib/blabbermouth/version.rb
|
72
|
+
- spec/blabbermouth/blabber_spec.rb
|
73
|
+
- spec/blabbermouth/gawkers/base_spec.rb
|
74
|
+
- spec/blabbermouth/gawkers/stdout_spec.rb
|
75
|
+
- spec/blabbermouth_spec.rb
|
108
76
|
- spec/spec_helper.rb
|
109
77
|
- spec/support/capture_stdout.rb
|
78
|
+
- spec/support/gawker.rb
|
110
79
|
homepage: http://github.com/markrebec/blabbermouth
|
111
80
|
licenses: []
|
112
81
|
metadata: {}
|
@@ -131,5 +100,10 @@ signing_key:
|
|
131
100
|
specification_version: 4
|
132
101
|
summary: Blabs your business to various datastores
|
133
102
|
test_files:
|
103
|
+
- spec/blabbermouth_spec.rb
|
134
104
|
- spec/spec_helper.rb
|
135
105
|
- spec/support/capture_stdout.rb
|
106
|
+
- spec/support/gawker.rb
|
107
|
+
- spec/blabbermouth/blabber_spec.rb
|
108
|
+
- spec/blabbermouth/gawkers/base_spec.rb
|
109
|
+
- spec/blabbermouth/gawkers/stdout_spec.rb
|