json-schema_builder 0.3.0 → 0.3.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '095b7ab204946bf21d11560cfce5aded0284bcc2'
4
- data.tar.gz: d36a58b116d0ab3677c76fb3235f5c138a76e0ef
3
+ metadata.gz: 84f7722dca12970cabc9b5a3e3f464883c34272c
4
+ data.tar.gz: dbb78e125209b463035cbd05d29abbff4da0e95a
5
5
  SHA512:
6
- metadata.gz: '0883e8aff0dd4d1279f8290e9707bf2997a1b4c8510a1bc0b48164de7b402f9b2c79fab754ec9b3c7a3b935b77b8a536bff218319133ee6bc7a582e662ddefa0'
7
- data.tar.gz: 9ea5f6d0668321cfb023acc96ee418a2b0ea22ede9d0811b8e71d50ae365d7637adec06d97f207cff54a23b0eecd4c237c7cdb192700b2965ef8af3002d64d51
6
+ metadata.gz: a98084c33aedabf1fc46b37a56ff71da7ecf179013bac5d8e4edaf4292a88ba4ea5f8e49655b39f115b6525c8b7d87f7c80fa3c7f7aa17a721620790b55adf37
7
+ data.tar.gz: 907cabeb1f50698e2d7c4103a43c273521ddba15dfeac29fcdc438563d697577675bae8dd764052bbaae8a8a3d99c9305dc98329a025d46e8544c46acaba5af7
@@ -9,13 +9,23 @@ module JSON
9
9
  end
10
10
 
11
11
  def merge(schema)
12
- self.class.new data.deep_merge(schema.data)
12
+ self.class.new _deep_merge(data, schema.data)
13
13
  end
14
14
 
15
15
  def merge!(schema)
16
- @data = data.deep_merge schema.data
16
+ @data = _deep_merge(data, schema.data)
17
17
  self
18
18
  end
19
+
20
+ def _deep_merge(this, other)
21
+ this.deep_merge(other) do |current_key, this_value, other_value|
22
+ if this_value.is_a?(::Array) && other_value.is_a?(::Array)
23
+ this_value + other_value
24
+ else
25
+ other_value
26
+ end
27
+ end
28
+ end
19
29
  end
20
30
  end
21
31
  end
@@ -1,5 +1,5 @@
1
1
  module JSON
2
2
  module SchemaBuilder
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
  end
5
5
  end
@@ -1,35 +1,59 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe JSON::SchemaBuilder::Schema, type: :unit do
4
- let(:schema){ described_class.new a: 1, b: { c: 3 } }
5
- let(:other){ described_class.new a: 2, "b" => { d: 4 } }
4
+ let(:schema){ described_class.new a: 1, b: { c: 3 }, array: [123, { foo: 1, bar: { baz: 0 }}] }
5
+ let(:other){ described_class.new a: 2, "b" => { d: 4 }, array: [456, { foo: 2, bar: { qux: 1 }}] }
6
+ let(:merged) do
7
+ {
8
+ "a" => 2,
9
+ "b" => {
10
+ "c" => 3,
11
+ "d" => 4
12
+ },
13
+ "array" => [
14
+ 123, {
15
+ "foo" => 1,
16
+ "bar" => {
17
+ "baz" => 0,
18
+ }
19
+ },
20
+ 456, {
21
+ "foo" => 2,
22
+ "bar" => {
23
+ "qux" => 1
24
+ }
25
+ }
26
+ ]
27
+ }
28
+ end
29
+
6
30
  its(:data){ is_expected.to be_a(HashWithIndifferentAccess) }
7
31
 
8
32
  describe '#merge' do
9
33
  it 'should deep merge' do
10
- merged = schema.merge other
11
- expect(merged).to be_a described_class
12
- expect(merged.to_h).to eql "a" => 2, "b" => { "c" => 3, "d" => 4 }
34
+ merged_schema = schema.merge other
35
+ expect(merged_schema).to be_a described_class
36
+ expect(merged_schema.data).to eql merged
13
37
  end
14
38
 
15
39
  it 'should not modify the source schema' do
16
- expect{ schema.merge other }.to_not change{ schema.to_h }
40
+ expect{ schema.merge other }.to_not change{ schema.data }
17
41
  end
18
42
 
19
43
  it 'should not modify the merging schema' do
20
- expect{ schema.merge other }.to_not change{ other.to_h }
44
+ expect{ schema.merge other }.to_not change{ other.data }
21
45
  end
22
46
  end
23
47
 
24
48
  describe '#merge!' do
25
49
  it 'should deep merge in place' do
26
- merged = schema.merge! other
27
- expect(merged).to be_a described_class
28
- expect(merged.to_h).to eql "a" => 2, "b" => { "c" => 3, "d" => 4 }
50
+ merged_schema = schema.merge! other
51
+ expect(merged_schema).to be_a described_class
52
+ expect(merged_schema.data).to eql merged
29
53
  end
30
54
 
31
55
  it 'should not modify the merging schema' do
32
- expect{ schema.merge! other }.to_not change { other.to_h }
56
+ expect{ schema.merge! other }.to_not change { other.data }
33
57
  end
34
58
  end
35
59
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schema_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Parrish