json-schema_builder 0.2.1 → 0.3.0

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: b9d8f8342dec85f473fec720fefb55c0a584e6b7
4
- data.tar.gz: 60d64252fd465336fda5a32b012860002e658c7b
3
+ metadata.gz: '095b7ab204946bf21d11560cfce5aded0284bcc2'
4
+ data.tar.gz: d36a58b116d0ab3677c76fb3235f5c138a76e0ef
5
5
  SHA512:
6
- metadata.gz: 15c9cb066c9fc51ff075d9c77142e7a43c9f04f25cade97e4864d3672deb4e9b0da57bbb57856daa9766ad1e281766d75ec4a48a5a408a6cf9c4f2827fbef600
7
- data.tar.gz: 302be39bebe17e01cc5b14af72c6e0ac3483ceb680f3ace8405ed36c14b734af538bfa2c9a020df8258e2f3c69bcc434389003ba442c744831ff8264af35ba6f
6
+ metadata.gz: '0883e8aff0dd4d1279f8290e9707bf2997a1b4c8510a1bc0b48164de7b402f9b2c79fab754ec9b3c7a3b935b77b8a536bff218319133ee6bc7a582e662ddefa0'
7
+ data.tar.gz: 9ea5f6d0668321cfb023acc96ee418a2b0ea22ede9d0811b8e71d50ae365d7637adec06d97f207cff54a23b0eecd4c237c7cdb192700b2965ef8af3002d64d51
data/.pryrc ADDED
@@ -0,0 +1,4 @@
1
+ Pry.commands.alias_command 'c', 'continue'
2
+ Pry.commands.alias_command 's', 'step'
3
+ Pry.commands.alias_command 'n', 'next'
4
+ Pry.commands.alias_command 'f', 'finish'
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency 'rake', '>= 10.0'
23
23
  spec.add_development_dependency 'rspec', '~> 3.4'
24
24
  spec.add_development_dependency 'rspec-its'
25
- spec.add_development_dependency 'pry'
25
+ spec.add_development_dependency 'pry-byebug'
26
26
  spec.add_dependency 'activesupport', '>= 4.0'
27
27
  spec.add_dependency 'json-schema', '>= 2'
28
28
  end
@@ -11,8 +11,8 @@ module JSON
11
11
 
12
12
  def items(*args, &block)
13
13
  opts = args.extract_options!
14
- schema.items = args.first
15
- schema.items ||= items_entity(opts, &block).as_json
14
+ schema[:items] = args.first
15
+ schema[:items] ||= items_entity(opts, &block).as_json
16
16
  end
17
17
 
18
18
  protected
@@ -52,7 +52,7 @@ module JSON
52
52
  end
53
53
 
54
54
  def as_json
55
- schema.to_h.as_json
55
+ schema.as_json
56
56
  end
57
57
 
58
58
  def respond_to?(method_name, include_all = false)
@@ -22,12 +22,12 @@ module JSON
22
22
  def required(*values)
23
23
  case values
24
24
  when []
25
- @schema.required
25
+ @schema[:required]
26
26
  when [true]
27
27
  @parent.required ||= []
28
28
  @parent.required << @name
29
29
  else
30
- @schema.required = values.flatten
30
+ @schema[:required] = values.flatten
31
31
  end
32
32
  end
33
33
  alias_method :required=, :required
@@ -1,14 +1,19 @@
1
- require 'ostruct'
2
-
3
1
  module JSON
4
2
  module SchemaBuilder
5
- class Schema < OpenStruct
3
+ class Schema
4
+ attr_reader :data
5
+ delegate :[], :[]=, :to_h, :as_json, to: :data
6
+
7
+ def initialize(hash = {})
8
+ @data = hash.with_indifferent_access
9
+ end
10
+
6
11
  def merge(schema)
7
- self.class.new to_h.deep_stringify_keys.deep_merge(schema.to_h.deep_stringify_keys)
12
+ self.class.new data.deep_merge(schema.data)
8
13
  end
9
14
 
10
15
  def merge!(schema)
11
- @table = to_h.deep_stringify_keys.deep_merge schema.to_h.deep_stringify_keys
16
+ @data = data.deep_merge schema.data
12
17
  self
13
18
  end
14
19
  end
@@ -1,5 +1,5 @@
1
1
  module JSON
2
2
  module SchemaBuilder
3
- VERSION = '0.2.1'
3
+ VERSION = '0.3.0'
4
4
  end
5
5
  end
@@ -18,7 +18,7 @@ RSpec.shared_context 'an entity with a parent' do
18
18
  let(:parent){ OpenStruct.new children: [], required: [] }
19
19
  subject do
20
20
  JSON::SchemaBuilder::Entity.new 'name', title: 'test', parent: parent do
21
- schema.evaluated_block = true
21
+ schema[:evaluated_block] = true
22
22
  end
23
23
  end
24
24
  end
@@ -23,13 +23,13 @@ RSpec.describe JSON::SchemaBuilder::Entity, type: :unit do
23
23
  end
24
24
 
25
25
  it 'should delegate the reader to the schema' do
26
- subject.schema.test = 1
26
+ subject.schema[:test] = 1
27
27
  expect(subject.test).to eql 1
28
28
  end
29
29
 
30
30
  it 'should delegate the writer to the schema' do
31
- subject.test = 1
32
- expect(subject.schema.test).to eql 1
31
+ subject.schema[:test] = 1
32
+ expect(subject.schema[:test]).to eql 1
33
33
  end
34
34
 
35
35
  it 'should accept function-style writes' do
@@ -38,38 +38,38 @@ RSpec.describe JSON::SchemaBuilder::Entity, type: :unit do
38
38
  end
39
39
 
40
40
  it 'should snakeCase attribute reads' do
41
- subject.schema.testName = 1
41
+ subject.schema[:testName] = 1
42
42
  expect(subject.test_name).to eql 1
43
43
  end
44
44
 
45
45
  it 'should snakeCase attribute writes' do
46
46
  subject.test_name = 1
47
- expect(subject.schema.testName).to eql 1
47
+ expect(subject.schema[:testName]).to eql 1
48
48
  end
49
49
 
50
50
  it 'should handle array argument reads' do
51
- subject.schema.testList = [1, 2, 3]
51
+ subject.schema[:testList] = [1, 2, 3]
52
52
  expect(subject.test_list).to eql [1, 2, 3]
53
53
  end
54
54
 
55
55
  it 'should handle array argument writes' do
56
56
  subject.test_list = [1, 2, 3]
57
- expect(subject.schema.testList).to eql [1, 2, 3]
57
+ expect(subject.schema[:testList]).to eql [1, 2, 3]
58
58
  end
59
59
 
60
60
  it 'should handle array argument lists' do
61
61
  subject.test_list 1, 2, 3
62
- expect(subject.schema.testList).to eql [1, 2, 3]
62
+ expect(subject.schema[:testList]).to eql [1, 2, 3]
63
63
  end
64
64
 
65
65
  it 'should handle arbitrary key writes' do
66
66
  subject.test_as 1
67
- expect(subject.schema.testAs).to be_nil
68
- expect(subject.schema.testOther).to eql 1
67
+ expect(subject.schema[:testAs]).to be_nil
68
+ expect(subject.schema[:testOther]).to eql 1
69
69
  end
70
70
 
71
71
  it 'should handle arbitrary key reads' do
72
- subject.schema.testOther = 1
72
+ subject.schema[:testOther] = 1
73
73
  expect(subject.test_as).to eql 1
74
74
  end
75
75
  end
@@ -80,7 +80,7 @@ RSpec.describe JSON::SchemaBuilder::Entity, type: :unit do
80
80
  its(:name){ is_expected.to eql 'name' }
81
81
  its(:title){ is_expected.to eql 'test' }
82
82
  its(:parent){ is_expected.to eql parent }
83
- its('schema.evaluated_block'){ is_expected.to be true }
83
+ its('schema.data'){ is_expected.to include evaluated_block: true }
84
84
  its('parent.children'){ is_expected.to include subject }
85
85
  end
86
86
 
@@ -136,7 +136,7 @@ RSpec.describe JSON::SchemaBuilder::Entity, type: :unit do
136
136
  include_context 'an entity'
137
137
 
138
138
  it 'should delegate to schema' do
139
- expect(subject.schema).to receive_message_chain :'to_h.as_json'
139
+ expect(subject.schema).to receive(:as_json)
140
140
  subject.as_json
141
141
  end
142
142
  end
@@ -3,13 +3,13 @@ require 'spec_helper'
3
3
  RSpec.describe JSON::SchemaBuilder::Schema, type: :unit do
4
4
  let(:schema){ described_class.new a: 1, b: { c: 3 } }
5
5
  let(:other){ described_class.new a: 2, "b" => { d: 4 } }
6
- it{ is_expected.to be_a OpenStruct }
6
+ its(:data){ is_expected.to be_a(HashWithIndifferentAccess) }
7
7
 
8
8
  describe '#merge' do
9
9
  it 'should deep merge' do
10
10
  merged = schema.merge other
11
11
  expect(merged).to be_a described_class
12
- expect(merged.to_h).to eql a: 2, b: { "c" => 3, "d" => 4 }
12
+ expect(merged.to_h).to eql "a" => 2, "b" => { "c" => 3, "d" => 4 }
13
13
  end
14
14
 
15
15
  it 'should not modify the source schema' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-schema_builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Parrish
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2017-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: pry
70
+ name: pry-byebug
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -116,6 +116,7 @@ extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
118
  - ".gitignore"
119
+ - ".pryrc"
119
120
  - ".rspec"
120
121
  - ".travis.yml"
121
122
  - Gemfile