rumbrl 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/rumbrl/grumble.rb +2 -0
- data/lib/rumbrl/smash.rb +2 -2
- data/lib/rumbrl/version.rb +1 -1
- data/spec/rumbrl/grumble_spec.rb +3 -1
- data/spec/rumbrl/smash_spec.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9df154c45e87dfaba90a89c8b7d27b72d892bc32
|
4
|
+
data.tar.gz: 37d72e10c60b45e74703cc2ac2eed95081228d16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec8067e052e6da3f7067b1a4881755b096a92f7b1c9a6f522e5939462c5480e46213df15bd34d9ee6220d052874b0445fa00665ef04cae3b1bfcce4ce35f562d
|
7
|
+
data.tar.gz: 72295fd53f6704373a10fc771b6d24e8620abb6b4fe1531f643ca645ca7a32cce1b92227ca04a253c96870dbe45604f03b8fee4ea7b9b07e4b04508f3fa62da2
|
data/Gemfile.lock
CHANGED
data/lib/rumbrl/grumble.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rumbrl/log'
|
2
|
+
require 'rumbrl/smash'
|
2
3
|
|
3
4
|
module Rumbrl
|
4
5
|
# Behance specific logger
|
@@ -13,6 +14,7 @@ module Rumbrl
|
|
13
14
|
|
14
15
|
def method_missing(name, channel, message, **args)
|
15
16
|
format = BASE_LOG_FORMAT
|
17
|
+
args = Smash.flatten(args)
|
16
18
|
args.each do |k, v|
|
17
19
|
format += " #{k.to_s.upcase}='#{v.to_s.gsub("'", '"')}'"
|
18
20
|
end
|
data/lib/rumbrl/smash.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Rumbrl
|
2
2
|
# serializes & flattens hashes
|
3
3
|
class Smash
|
4
|
-
def self.
|
4
|
+
def self.flatten(namespace: '', **target)
|
5
5
|
res = {}
|
6
6
|
# flattens a hash
|
7
7
|
target.each do |k, v|
|
8
8
|
cur_nspace = build_namespace(namespace, k)
|
9
9
|
if v.is_a? Hash
|
10
|
-
res.update
|
10
|
+
res.update flatten(**v, namespace: cur_nspace)
|
11
11
|
next
|
12
12
|
end
|
13
13
|
res[cur_nspace.to_sym] = v
|
data/lib/rumbrl/version.rb
CHANGED
data/spec/rumbrl/grumble_spec.rb
CHANGED
@@ -35,9 +35,11 @@ describe Rumbrl::Grumble do
|
|
35
35
|
log = Rumbrl::Grumble.new('path/to/log', 'weekly', 123)
|
36
36
|
|
37
37
|
line = /\[.*\] LEVEL='INFO' CHANNEL='channel' MESSAGE='msg' FOO='bar'\n/
|
38
|
+
hash = { foo: 'bar' }
|
38
39
|
expect_any_instance_of(Logger::LogDevice).to receive(:write).with(line)
|
40
|
+
expect(Rumbrl::Smash).to receive(:flatten).with(hash).and_return(hash)
|
39
41
|
|
40
|
-
log.info('channel', 'msg',
|
42
|
+
log.info('channel', 'msg', hash)
|
41
43
|
end
|
42
44
|
end
|
43
45
|
end
|
data/spec/rumbrl/smash_spec.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
2
|
|
3
3
|
describe Rumbrl::Smash do
|
4
|
-
describe '.
|
4
|
+
describe '.flatten' do
|
5
5
|
it 'does not change flat hash' do
|
6
6
|
target = { bar: 'foo' }
|
7
|
-
expect(Rumbrl::Smash.
|
7
|
+
expect(Rumbrl::Smash.flatten(target)).to eql target
|
8
8
|
end
|
9
9
|
|
10
10
|
it 'flattens nested hashes with namespaced keys' do
|
11
11
|
target = { bar: 'foo', baz: { wee: 'boo' } }
|
12
12
|
flattened = { bar: 'foo', baz_wee: 'boo' }
|
13
|
-
expect(Rumbrl::Smash.
|
13
|
+
expect(Rumbrl::Smash.flatten(target)).to eql flattened
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|