activerecord_json_validator 0.5 → 0.5.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: e916b93c42c1f418b5138f0680f1f3c6da4caca6
4
- data.tar.gz: 891634217d8bf1d6430a919500bc05e0559e058a
3
+ metadata.gz: e122734c159cf841ab43d38bdc6efd2e4d554605
4
+ data.tar.gz: 96c99ba0cde8902483245991ccab6b2bc03870d6
5
5
  SHA512:
6
- metadata.gz: dcb7b8ae91f3eca385eab1d8480b9ad60072c6f5ec9cf777565e5279db47946a17f8c280deae9972fdeec22e3e81caa7fc221dee89d19cc1a821b27d7729fd74
7
- data.tar.gz: 3eeda53bedb220bd51ea5cacf5e476cb6875acb8ef83fc78222f74e436ca4c3d89cd119544c904edae98a53e76cddd643a339b5654a8335acbc4fd20872c9e77
6
+ metadata.gz: 3d060208f9aebadac25bd9b6c3a72db71eb689e775c9a3be343c45f05d0e5d7a5e36c4b91a6341b2823c3b6b7bce7a2c2efe7a3b1972a0b4d97a618b3da2a759
7
+ data.tar.gz: 5aff819411acfe4a894c3e5f4d6422f7ffdef61c78cf07b8551025c8b7d0ab6794ed51283e9d90a1f4c479c32fe65622e2c548fd526ef7e2f0059ed560d04a72
@@ -56,11 +56,16 @@ protected
56
56
  end
57
57
  end
58
58
 
59
- def schema(record)
60
- schema = options.fetch(:schema)
61
- return schema unless schema.is_a?(Proc)
59
+ # Return a valid schema for JSON::Validator.fully_validate, recursively calling
60
+ # itself until it gets a non-Proc/non-Symbol value.
61
+ def schema(record, schema = nil)
62
+ schema ||= options.fetch(:schema)
62
63
 
63
- record.instance_exec(&schema)
64
+ case schema
65
+ when Proc then schema(record, record.instance_exec(&schema))
66
+ when Symbol then schema(record, record.send(schema))
67
+ else schema
68
+ end
64
69
  end
65
70
 
66
71
  def validatable_value(value)
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module JSONValidator
3
- VERSION = '0.5'
3
+ VERSION = '0.5.1'
4
4
  end
5
5
  end
@@ -93,25 +93,47 @@ describe JsonValidator do
93
93
  let(:options) { { attributes: [:foo], schema: schema_option } }
94
94
  let(:schema) { validator.send(:schema, record) }
95
95
 
96
- context 'with non-Proc schema' do
96
+ context 'with String schema' do
97
97
  let(:schema_option) { double(:schema) }
98
98
  let(:record) { double(:record) }
99
99
 
100
100
  it { expect(schema).to eql(schema_option) }
101
101
  end
102
102
 
103
- context 'with Proc schema' do
103
+ context 'with Proc schema returning a Proc returning a Proc' do
104
104
  let(:schema_option) { -> { dynamic_schema } }
105
105
  let(:record) { record_class.new }
106
106
  let(:record_class) do
107
107
  Class.new do
108
108
  def dynamic_schema
109
- :yay
109
+ -> { another_dynamic_schema }
110
+ end
111
+
112
+ def another_dynamic_schema
113
+ -> { what_another_dynamic_schema }
114
+ end
115
+
116
+ def what_another_dynamic_schema
117
+ 'yay'
118
+ end
119
+ end
120
+ end
121
+
122
+ it { expect(schema).to eql('yay') }
123
+ end
124
+
125
+ context 'with Symbol schema' do
126
+ let(:schema_option) { :dynamic_schema }
127
+ let(:record) { record_class.new }
128
+ let(:record_class) do
129
+ Class.new do
130
+ def dynamic_schema
131
+ 'foo'
110
132
  end
111
133
  end
112
134
  end
113
135
 
114
- it { expect(schema).to eql(:yay) }
136
+ it { expect(schema).to eql('foo') }
115
137
  end
116
138
  end
117
139
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_json_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémi Prévost
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-03 00:00:00.000000000 Z
11
+ date: 2015-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler