hash_generator 1.0.0 → 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: 11486c609a6d854ccfc88383ba41b6f67fffa149
4
- data.tar.gz: 0fbf0032512abf232454e4fe9d52c4309e6097c8
3
+ metadata.gz: 6d7ee8c683b8a5704fed550825256684cd58a432
4
+ data.tar.gz: 0c0340d70d34a2194744986871874ff326dc1a08
5
5
  SHA512:
6
- metadata.gz: c1190f1e92a7abb3a2b0f468094f98860f1d02842098231b23e1002271b1d5e839724ff97b8de17a054b154ccd26f03e48b58d04a054da44ea982166d1962969
7
- data.tar.gz: 8fedf12e04e6e589cb4d15da287189ffc702088a0ea5eb63759eb43397c4a4ec0382306b5b6074a7ee71ee95fb2c469618df862da07edfd34df795fc6d742160
6
+ metadata.gz: 54c333ceec77b9251c8ee273fb36247202eff37a5e8b758381c3f84c9e193a3f1db899e2f43b8a3aaa153861bd58d65c2b11f1c21318cc0506824008bd3b108d
7
+ data.tar.gz: 9cd06b2c637cb0f2281f01b32e3f6196ea906c3b42beba15b2cd5e0b39aa94a01ca3579d446d3370e53ca324bda2ca628c8349bdd40d44202a03aef83bce8596
@@ -1,5 +1,5 @@
1
1
  class HashGenerator
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
 
4
4
  def initialize
5
5
  @value = @scope = {}
@@ -18,6 +18,12 @@ class HashGenerator
18
18
  begin_scope({})
19
19
  end
20
20
 
21
+ def push_object
22
+ new_object
23
+ yield
24
+ push_scope
25
+ end
26
+
21
27
  def push_scope
22
28
  value = @scope
23
29
  end_scope
@@ -32,6 +38,18 @@ class HashGenerator
32
38
  @scope.store(key, value)
33
39
  end
34
40
 
41
+ def store_array(key)
42
+ new_array
43
+ yield
44
+ store_scope(key)
45
+ end
46
+
47
+ def store_object(key)
48
+ new_object
49
+ yield
50
+ store_scope(key)
51
+ end
52
+
35
53
  def store_scope(key)
36
54
  value = @scope
37
55
  end_scope
@@ -5,8 +5,20 @@ RSpec.describe HashGenerator do
5
5
 
6
6
  subject { generator.to_h }
7
7
 
8
+ describe '#push_object' do
9
+ it 'begins a new object scope, yields, then pushes the object into the outer scope' do
10
+ generator.new_array
11
+ generator.push_object do
12
+ generator.store(:key, 1)
13
+ end
14
+ generator.store_scope(:array)
15
+
16
+ should eq(:array => [{:key => 1}])
17
+ end
18
+ end
19
+
8
20
  describe '#push_scope' do
9
- it 'pushes an object into the outer scope' do
21
+ it 'pushes the current scope into the outer scope' do
10
22
  generator.new_array
11
23
  generator.new_object
12
24
  generator.store(:key, 1)
@@ -38,6 +50,28 @@ RSpec.describe HashGenerator do
38
50
  end
39
51
  end
40
52
 
53
+ describe '#store_array' do
54
+ it 'begins a new array scope, yields, then stores the array at the given key' do
55
+ generator.store_array(:objects) do
56
+ generator.new_object
57
+ generator.store(:key, 1)
58
+ generator.push_scope
59
+ end
60
+
61
+ should eq(:objects => [{:key => 1}])
62
+ end
63
+ end
64
+
65
+ describe '#store_object' do
66
+ it 'begins a new object scope, yields, then stores the object at the given key' do
67
+ generator.store_object(:object) do
68
+ generator.store(:key, 1)
69
+ end
70
+
71
+ should eq(:object => {:key => 1})
72
+ end
73
+ end
74
+
41
75
  describe '#store_scope' do
42
76
  it 'stores the current scope in the outer scope at the given key' do
43
77
  generator.new_object
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dray Lacy