activerecord_json_validator 0.5 → 0.5.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e122734c159cf841ab43d38bdc6efd2e4d554605
|
4
|
+
data.tar.gz: 96c99ba0cde8902483245991ccab6b2bc03870d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d060208f9aebadac25bd9b6c3a72db71eb689e775c9a3be343c45f05d0e5d7a5e36c4b91a6341b2823c3b6b7bce7a2c2efe7a3b1972a0b4d97a618b3da2a759
|
7
|
+
data.tar.gz: 5aff819411acfe4a894c3e5f4d6422f7ffdef61c78cf07b8551025c8b7d0ab6794ed51283e9d90a1f4c479c32fe65622e2c548fd526ef7e2f0059ed560d04a72
|
@@ -56,11 +56,16 @@ protected
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
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)
|
data/spec/json_validator_spec.rb
CHANGED
@@ -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
|
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
|
-
|
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(
|
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:
|
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-
|
11
|
+
date: 2015-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|