json_model_rb 0.1.24 → 0.1.26

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: 9de086a259003cabd719e1d136f8849943f7ddbe03dc159e8b222a9fad906e16
4
- data.tar.gz: f56d53d6c70c97545a12a7dab8426a0a19afb1a26c53508a1f029def5ff5bf94
3
+ metadata.gz: ccad36b0642e02de1ad6bc289113f5191c6e4182660a94c89b874d7717384cdd
4
+ data.tar.gz: 18a055eae6f73a38744cab3c5b1f925e032d9ef56e7f01139733dc3c29ddd967
5
5
  SHA512:
6
- metadata.gz: d1eb31d9a5459f2fc18a9b066712c7eec233da44c34b4f7370fb801c5dd8995ff8387e312acd5d66e63b7b8a48c233760b8ad99d94a277a9d794cbdc10065170
7
- data.tar.gz: 894d35b00daef15e54c823f0889d940746df5bff569042d25e9c070973c2b6d59804058b7515da2752db3d57ef364cb1ca0d2a15022b1ed6e2ed291b8607b45f
6
+ metadata.gz: 407a9b05cd4e25ca67a77a2fb74a0b0731e9487e690d47e2325afa9c1b42cb9abe5b73cc19a62c06152595ac9986f3607a827763b0f64e7221d5eac2f552d5d3
7
+ data.tar.gz: 5e61b492ece84552330e02d495b11447a6c804f42ba75938a30a3c3f83b5056c6c2011c809b05bba13d2627dec8ca889caa5a1df729ef3977dc67a1679ba040a
@@ -9,11 +9,10 @@ module JsonModel
9
9
  include(SchemaMeta)
10
10
 
11
11
  class_methods do
12
- # @param [::Object] json
12
+ # @param [Hash] attributes
13
13
  # @return [::Object, nil]
14
- def from_json(json)
15
- attributes = json.transform_keys { |key| invert_alias(key) }
16
- new(attributes)
14
+ def new(attributes = {})
15
+ super(attributes.transform_keys { |key| invert_alias(key) })
17
16
  end
18
17
 
19
18
  # @param [Symbol] key
@@ -76,10 +75,10 @@ module JsonModel
76
75
 
77
76
  # @return [Array<Builder>]
78
77
  def builders
79
- @builders ||= @local_builders + @schema
80
- .type
81
- .select { |type| parent_keys.include?(type) }
82
- .map { |type| Builder.for(type) }
78
+ @builders ||= local_builders + @schema
79
+ .type
80
+ .select { |type| parent_keys.include?(type) }
81
+ .map { |type| Builder.for(type) }
83
82
  end
84
83
 
85
84
  # @return [Array<Class>]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonModel
4
- VERSION = '0.1.24'
4
+ VERSION = '0.1.26'
5
5
  end
@@ -14,7 +14,7 @@ RSpec.describe('File system schema') do
14
14
  end
15
15
 
16
16
  attribute(:type, JsonModel::Types::String.constrained(eql: 'disk'))
17
- attribute(:device, JsonModel::Types::String.constrained(format: %r{\A/dev/[^/]+(/[^/]+)*\z}))
17
+ attribute(:device, JsonModel::Types::String.constrained(format: %r{\A/dev/[^/]+(/[^/]+)*\z}).as(:Device))
18
18
  end,
19
19
  )
20
20
 
@@ -138,12 +138,12 @@ RSpec.describe('File system schema') do
138
138
  const: 'disk',
139
139
  type: 'string',
140
140
  },
141
- device: {
141
+ Device: {
142
142
  type: 'string',
143
143
  pattern: '\\A/dev/[^/]+(/[^/]+)*\\z',
144
144
  },
145
145
  },
146
- required: %i(device type),
146
+ required: %i(Device type),
147
147
  type: 'object',
148
148
  },
149
149
  DiskUuid: {
@@ -194,7 +194,7 @@ RSpec.describe('File system schema') do
194
194
 
195
195
  it('can instantiate a model') do
196
196
  instance = Fstab.new(
197
- storage: { device: '/dev/sda1', type: 'disk' },
197
+ storage: { Device: '/dev/sda1', type: 'disk' },
198
198
  fstype: 'ext4',
199
199
  options: %w(rw noatime),
200
200
  )
@@ -205,4 +205,4 @@ RSpec.describe('File system schema') do
205
205
  expect(instance.options).to(eq(%w(rw noatime)))
206
206
  expect(instance.readonly).to(be_nil)
207
207
  end
208
- end
208
+ end
data/spec/schema_spec.rb CHANGED
@@ -39,7 +39,7 @@ RSpec.describe(JsonModel::Schema) do
39
39
  end
40
40
  end
41
41
 
42
- describe('.from_json') do
42
+ describe('.new') do
43
43
  before do
44
44
  stub_const(
45
45
  'Foo',
@@ -57,12 +57,12 @@ RSpec.describe(JsonModel::Schema) do
57
57
  end
58
58
 
59
59
  it('parent can be instantiated from json') do
60
- instance = Foo.from_json({ fooBar: 'baz' })
60
+ instance = Foo.new({ fooBar: 'baz' })
61
61
  expect(instance.foo_bar).to(eq('baz'))
62
62
  end
63
63
 
64
64
  it('child can be instantiated from json') do
65
- instance = Bar.from_json({ fooBar: 'baz' })
65
+ instance = Bar.new({ fooBar: 'baz' })
66
66
  expect(instance.foo_bar).to(eq('baz'))
67
67
  end
68
68
  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.24
4
+ version: 0.1.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Gillesberger