rumbrl 1.0.1 → 1.1.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 +4 -1
- data/lib/rumbrl/ext/hash.rb +8 -0
- data/lib/rumbrl/smash.rb +9 -8
- data/lib/rumbrl/version.rb +1 -1
- data/spec/rumbrl/smash_spec.rb +41 -8
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27332cc6d1eaabc7476a24c274191fd093b83c78
|
4
|
+
data.tar.gz: d8585394da751a6a06e117e0fada8e9a834822b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31db318d173b6ba61d51476ec141dd8c9f842f457a694bed407c99391fbfd651feed9d6c0a6918d05d8b987e84b15de133827e757aea418535e873e249c23b4d
|
7
|
+
data.tar.gz: be7d23e906fec0f5a0d7faa3e82c20bff8e5f5e326d1e215c00a9a29fd46dc2133f2fbac16e4e85bc71777960322dc1119ac424ba8468b2128ae8868fa0ca2fd
|
data/Gemfile.lock
CHANGED
data/lib/rumbrl/smash.rb
CHANGED
@@ -1,17 +1,18 @@
|
|
1
|
+
require 'rumbrl/ext/hash'
|
2
|
+
|
1
3
|
module Rumbrl
|
2
4
|
# serializes & flattens hashes
|
3
5
|
class Smash
|
4
6
|
def self.flatten(target, namespace: '')
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
if v.
|
9
|
-
res.update
|
10
|
-
|
7
|
+
target.each_with_object({}) do |(k, v), res|
|
8
|
+
cur_namespace = build_namespace(namespace, k)
|
9
|
+
|
10
|
+
if v.respond_to?(:to_log)
|
11
|
+
res.update(flatten(v.to_log, namespace: cur_namespace))
|
12
|
+
else
|
13
|
+
res.update(cur_namespace.to_sym => v)
|
11
14
|
end
|
12
|
-
res[cur_nspace.to_sym] = v
|
13
15
|
end
|
14
|
-
res
|
15
16
|
end
|
16
17
|
|
17
18
|
def self.build_namespace(prev = '', cur = '')
|
data/lib/rumbrl/version.rb
CHANGED
data/spec/rumbrl/smash_spec.rb
CHANGED
@@ -1,22 +1,55 @@
|
|
1
1
|
require_relative '../spec_helper'
|
2
2
|
|
3
|
+
# Mock class for testing
|
4
|
+
class PopTart
|
5
|
+
def to_log
|
6
|
+
{
|
7
|
+
frosting: 'vanilla',
|
8
|
+
filling: 'strawberry'
|
9
|
+
}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class NotPopTart
|
14
|
+
end
|
15
|
+
|
3
16
|
describe Rumbrl::Smash do
|
4
17
|
describe '.flatten' do
|
5
18
|
it 'does not change flat hash' do
|
6
|
-
|
7
|
-
expect(Rumbrl::Smash.flatten(
|
19
|
+
source = { bar: 'foo' }
|
20
|
+
expect(Rumbrl::Smash.flatten(source)).to eql(source)
|
8
21
|
end
|
9
22
|
|
10
23
|
it 'flattens nested hashes with namespaced keys' do
|
11
|
-
|
12
|
-
|
13
|
-
expect(Rumbrl::Smash.flatten(
|
24
|
+
source = { bar: 'foo', baz: { wee: 'boo' } }
|
25
|
+
target = { bar: 'foo', baz_wee: 'boo' }
|
26
|
+
expect(Rumbrl::Smash.flatten(source)).to eql(target)
|
14
27
|
end
|
15
28
|
|
16
29
|
it 'flattens nested hashes with mixed keys' do
|
17
|
-
|
18
|
-
|
19
|
-
expect(Rumbrl::Smash.flatten(
|
30
|
+
source = { 'bar' => 'foo', baz: { 'wee' => 'boo' } }
|
31
|
+
target = { bar: 'foo', baz_wee: 'boo' }
|
32
|
+
expect(Rumbrl::Smash.flatten(source)).to eql(target)
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'given an object' do
|
36
|
+
context 'that responds to `to_log`' do
|
37
|
+
it 'flattens hash representation of the object' do
|
38
|
+
source = { bar: 'foo', poptart: PopTart.new }
|
39
|
+
target = { bar: 'foo',
|
40
|
+
poptart_frosting: 'vanilla',
|
41
|
+
poptart_filling: 'strawberry' }
|
42
|
+
expect(Rumbrl::Smash.flatten(source)).to eql(target)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'that does not responds to `to_log`' do
|
47
|
+
it 'does not flatten the object' do
|
48
|
+
not_poptart = NotPopTart.new
|
49
|
+
source = { bar: 'foo', poptart: not_poptart }
|
50
|
+
expect(Rumbrl::Smash.flatten(source)).to eql(source)
|
51
|
+
end
|
52
|
+
end
|
20
53
|
end
|
21
54
|
end
|
22
55
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rumbrl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chr0n1x
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubocop
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- README.md
|
97
97
|
- lib/rumbrl.rb
|
98
98
|
- lib/rumbrl/env.rb
|
99
|
+
- lib/rumbrl/ext/hash.rb
|
99
100
|
- lib/rumbrl/factory.rb
|
100
101
|
- lib/rumbrl/formatter.rb
|
101
102
|
- lib/rumbrl/grumble.rb
|
@@ -138,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
139
|
version: '0'
|
139
140
|
requirements: []
|
140
141
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.
|
142
|
+
rubygems_version: 2.5.0
|
142
143
|
signing_key:
|
143
144
|
specification_version: 4
|
144
145
|
summary: ''
|
@@ -150,3 +151,4 @@ test_files:
|
|
150
151
|
- spec/rumbrl/log_spec.rb
|
151
152
|
- spec/rumbrl/smash_spec.rb
|
152
153
|
- spec/spec_helper.rb
|
154
|
+
has_rdoc:
|