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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84d0262471cebd69cf1a604c7f2dd221efa8138f
4
- data.tar.gz: 8940adf061ecdbfb684a3672afb9bdf864495262
3
+ metadata.gz: 27332cc6d1eaabc7476a24c274191fd093b83c78
4
+ data.tar.gz: d8585394da751a6a06e117e0fada8e9a834822b0
5
5
  SHA512:
6
- metadata.gz: 76f38bcbb4deae96405f57f5082cc573c8d3631fca12cede47430e365fb3a95c054cc93dc5be716ec4517b1dd8fb1be2243e4b6715870b61dc68fca317c2cd42
7
- data.tar.gz: 4e6c8c0377074d4f67b3301707f5254b48814068c3f291c64a42a3f4295053d670950746641dbb3f3428710a139c907f1b08f9c2b451e688c7867dbb9351d7e3
6
+ metadata.gz: 31db318d173b6ba61d51476ec141dd8c9f842f457a694bed407c99391fbfd651feed9d6c0a6918d05d8b987e84b15de133827e757aea418535e873e249c23b4d
7
+ data.tar.gz: be7d23e906fec0f5a0d7faa3e82c20bff8e5f5e326d1e215c00a9a29fd46dc2133f2fbac16e4e85bc71777960322dc1119ac424ba8468b2128ae8868fa0ca2fd
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rumbrl (1.0.1)
4
+ rumbrl (1.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -60,3 +60,6 @@ DEPENDENCIES
60
60
  rubocop (~> 0.24)
61
61
  rumbrl!
62
62
  shoulda-matchers (~> 2.7)
63
+
64
+ BUNDLED WITH
65
+ 1.11.2
@@ -0,0 +1,8 @@
1
+ # Extensions for native Hash to allow for log ingestion
2
+ module HashExtensions
3
+ def to_log
4
+ to_hash
5
+ end
6
+ end
7
+
8
+ ::Hash.include(HashExtensions)
@@ -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
- res = {}
6
- target.each_pair do |k, v|
7
- cur_nspace = build_namespace(namespace, k)
8
- if v.is_a? Hash
9
- res.update flatten(v, namespace: cur_nspace)
10
- next
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 = '')
@@ -2,5 +2,5 @@
2
2
 
3
3
  # version const for gem
4
4
  module Rumbrl
5
- VERSION = '1.0.1'
5
+ VERSION = '1.1.0'
6
6
  end
@@ -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
- target = { bar: 'foo' }
7
- expect(Rumbrl::Smash.flatten(target)).to eql target
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
- target = { bar: 'foo', baz: { wee: 'boo' } }
12
- flattened = { bar: 'foo', baz_wee: 'boo' }
13
- expect(Rumbrl::Smash.flatten(target)).to eql flattened
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
- target = { 'bar' => 'foo', baz: { 'wee' => 'boo' } }
18
- flattened = { bar: 'foo', baz_wee: 'boo' }
19
- expect(Rumbrl::Smash.flatten(target)).to eql flattened
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.1
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: 2015-07-08 00:00:00.000000000 Z
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.2.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: