json_model_rb 0.1.8 → 0.1.10
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
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 98bb614ecc704ac48a1a6d72b079f26eae33b6e6e392c64309ef3dead031cef3
|
|
4
|
+
data.tar.gz: cae571a4e4f58b34a1c5add1135ebbe8382dcf588a40fcdca719343addaf66b5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0c7d8e9859704abbdc88e0659de62c34c586e448288e58063f80a7448a5c0c32ccf374146ed14488a1ee67f6a358e80f162fb4b9cd79a531b479c89bc5d814e0
|
|
7
|
+
data.tar.gz: 9a2ca8d4b13ee9ac3ff8fb6e68adca65bdad4a320f2216fe5a277842a1feacf5f5aa0b9f3049ab39658c3f6fa5f833339bfcca967e7782ce9068e9039dde8dfb
|
|
@@ -25,7 +25,7 @@ module JsonModel
|
|
|
25
25
|
elsif @types.any? { |type| json.is_a?(type) }
|
|
26
26
|
json
|
|
27
27
|
else
|
|
28
|
-
raise(Errors::TypeError, "Expected one of #{@
|
|
28
|
+
raise(Errors::TypeError, "Expected one of #{@types.join('/')}, got #{json.class} (#{json.inspect})")
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
end
|
data/lib/json_model/version.rb
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require('spec_helper')
|
|
4
|
+
|
|
5
|
+
RSpec.describe('User schema') do
|
|
6
|
+
it('todo') do
|
|
7
|
+
base_component = stub_const(
|
|
8
|
+
'BaseComponent',
|
|
9
|
+
Class.new do
|
|
10
|
+
include(JsonModel::Schema)
|
|
11
|
+
property(:type, type: String)
|
|
12
|
+
property(:styles, type: T::Array[String], optional: true)
|
|
13
|
+
end
|
|
14
|
+
)
|
|
15
|
+
text_component = stub_const(
|
|
16
|
+
'TextComponent',
|
|
17
|
+
Class.new(BaseComponent) do
|
|
18
|
+
include(JsonModel::Schema)
|
|
19
|
+
property(:type, type: T::Enum['text'])
|
|
20
|
+
property(:value, type: String)
|
|
21
|
+
end
|
|
22
|
+
)
|
|
23
|
+
number_component = stub_const(
|
|
24
|
+
'NumberComponent',
|
|
25
|
+
Class.new(BaseComponent) do
|
|
26
|
+
include(JsonModel::Schema)
|
|
27
|
+
property(:type, type: T::Const['number'])
|
|
28
|
+
property(:value, type: Integer)
|
|
29
|
+
end
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
all_component_types = ObjectSpace
|
|
33
|
+
.each_object(Class)
|
|
34
|
+
.select { |klass| klass.ancestors.include?(BaseComponent) && klass != BaseComponent }
|
|
35
|
+
grid_component = stub_const(
|
|
36
|
+
'GridComponent',
|
|
37
|
+
Class.new(BaseComponent) do
|
|
38
|
+
include(JsonModel::Schema)
|
|
39
|
+
property(:type, type: T::Const['grid'])
|
|
40
|
+
property(:components, type: T::Array[T::OneOf[*all_component_types]], optional: true, ref_mode: JsonModel::RefMode::EXTERNAL)
|
|
41
|
+
end
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
instance = GridComponent.new(
|
|
46
|
+
type: 'grid',
|
|
47
|
+
components: [{ type: 'text', value: 'foo' }, { type: 'number', value: 1 }],
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
expect(instance.components.first).to(be_instance_of(TextComponent))
|
|
51
|
+
expect(instance.components.last).to(be_instance_of(NumberComponent))
|
|
52
|
+
end
|
|
53
|
+
end
|
data/spec/type_spec/enum_spec.rb
CHANGED
|
@@ -34,7 +34,7 @@ RSpec.describe(JsonModel::TypeSpec::Enum) do
|
|
|
34
34
|
described_class
|
|
35
35
|
.new(1)
|
|
36
36
|
.register_validations(:foo, klass)
|
|
37
|
-
instance = klass.new(foo:
|
|
37
|
+
instance = klass.new(foo: 2)
|
|
38
38
|
|
|
39
39
|
expect(instance.valid?)
|
|
40
40
|
.to(be(false))
|
|
@@ -62,15 +62,6 @@ RSpec.describe(JsonModel::TypeSpec::Enum) do
|
|
|
62
62
|
.register_validations(:foo, klass)
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
-
it('fails the validation if nil') do
|
|
66
|
-
instance = klass.new(foo: nil)
|
|
67
|
-
|
|
68
|
-
expect(instance.valid?)
|
|
69
|
-
.to(be(false))
|
|
70
|
-
expect(instance.errors.map(&:type))
|
|
71
|
-
.to(eq(%i(inclusion)))
|
|
72
|
-
end
|
|
73
|
-
|
|
74
65
|
it('fails the validation if not allowed') do
|
|
75
66
|
instance = klass.new(foo: 0)
|
|
76
67
|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: json_model_rb
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.10
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Paul Gillesberger
|
|
@@ -141,6 +141,7 @@ files:
|
|
|
141
141
|
- lib/json_model/types/one_of.rb
|
|
142
142
|
- lib/json_model/version.rb
|
|
143
143
|
- spec/config_spec.rb
|
|
144
|
+
- spec/examples/component_spec.rb
|
|
144
145
|
- spec/examples/file_system_spec.rb
|
|
145
146
|
- spec/examples/user_spec.rb
|
|
146
147
|
- spec/json_model_spec.rb
|