json_model_rb 0.1.7 → 0.1.9

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: 91d9055f02d8e7422d6915d44620adbd1668ca5fcff577fe2cf0964412699153
4
- data.tar.gz: 447bfbd423aa8e176faf3844079e48d3a1e01f5e367778ca48b8e0f659f51928
3
+ metadata.gz: 49c30126ff23f7ec073ef981be5682bb6db7976e4d3f7fde6e5ad5c26b3fc7d8
4
+ data.tar.gz: 88e4abe3490277fc63c1f3b4d612dc398cb68e982c1038d00cf75fce7bff2759
5
5
  SHA512:
6
- metadata.gz: 7b99e2ddcbde5c4adec3138796292ff564ad19342ba32c7513bba90c7beac1b8522b6d1c62f7cf987840b08eadca5a2d3206ab892ba9cc36fa6760b71490f6bc
7
- data.tar.gz: 87247c327a4bbf77e171c7bf89389f616109dbc8a6e0b37d6ceb177bf2a3d89cd5def0c585d614d8f10ce4b91da589af3a7f042e005bca1ae60d3b3ba2b83bad
6
+ metadata.gz: 782eebf325932cd06bccf71c410e5a820868bf07989372da9b6329b8e3e2eaab68fea6c16e4d2234279d57cee3c831871c786507618914683b30ce57aec0bf37
7
+ data.tar.gz: 235dce29d095bab73e393c39b6912ffb1de547a52de845a4a3c309a14b7584baa816d5f71584a4ead8a1c2b64f5210956541e747ef059774a5c721c34647bcc1
@@ -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 #{@type.join('/')}, got #{json.class} (#{json.inspect})")
28
+ raise(Errors::TypeError, "Expected one of #{@types.join('/')}, got #{json.class} (#{json.inspect})")
29
29
  end
30
30
  end
31
31
  end
@@ -40,7 +40,7 @@ module JsonModel
40
40
  type
41
41
  when Class
42
42
  resolve_type_from_class(type, **options)
43
- when T::AllOf, T::AnyOf, T::Boolean, T::OneOf, T::Array, T::Enum
43
+ when T::AllOf, T::AnyOf, T::Boolean, T::OneOf, T::Array, T::Enum, T::Const
44
44
  type.to_type_spec(**options)
45
45
  else
46
46
  raise(ArgumentError, "Unsupported type: #{type}")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonModel
4
- VERSION = '0.1.7'
4
+ VERSION = '0.1.9'
5
5
  end
@@ -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
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.7
4
+ version: 0.1.9
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