json_model_rb 0.1.8 → 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: ae375731299ec26a890c6325c485b794599871c645e9345bb92492908f9bf3ae
4
- data.tar.gz: bfad9ced0dd6ecc9720b85bdd029b7e3078b84581aad4c2273866137459e1442
3
+ metadata.gz: 49c30126ff23f7ec073ef981be5682bb6db7976e4d3f7fde6e5ad5c26b3fc7d8
4
+ data.tar.gz: 88e4abe3490277fc63c1f3b4d612dc398cb68e982c1038d00cf75fce7bff2759
5
5
  SHA512:
6
- metadata.gz: 78c339093d60f4bb6d9d13f48ed21fc6d3f303f7821ac3b66c0ff90593c70fe962582db2fb5481b7399c66c607cd7af7072d9acbcc92dd706f9b4ec768b4b064
7
- data.tar.gz: 686ff812df589d267d6318b183c47c815184eb17cbd32d0d79b278216af4fdee70d8d04f39734d9545cf0fa89d8e5cf04b985f0874814d2dc9a3d18cdb2cf5cc
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonModel
4
- VERSION = '0.1.8'
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.8
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