schema_serializer 0.2.2 → 0.2.3
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a88a43d37245072aabcdb80815179a1b33a0214f9663f55333a1d493b09b940
|
4
|
+
data.tar.gz: 0f599ae0884b584751310a3350876ba066f510966c4028499d98f3b4d59bd986
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b67835d5764c9b898979fd6143baea0d8f2f53b8ee80ea47de47fe3424c710e80d3b61a25947a87908badff2d4d215c8101488be8b65220b39eeb79d41a65892
|
7
|
+
data.tar.gz: 9d6a75ff1f6ad70b7ff54a82bf0269bd8853f281cfbca86d5c6788c69b5cb02eda5484cdc847a4bf6852b67d3afd92025f32ef3b52791201bc66e558777b3472
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class SchemaSerializer
|
2
|
+
class Configuration
|
3
|
+
VALID_OPTIONS = [
|
4
|
+
:raise_on_null,
|
5
|
+
].freeze
|
6
|
+
|
7
|
+
attr_accessor *VALID_OPTIONS
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
reset
|
11
|
+
merge(options)
|
12
|
+
end
|
13
|
+
|
14
|
+
def merge(options)
|
15
|
+
options.keys.each { |key| send("#{key}=", options[key]) }
|
16
|
+
self
|
17
|
+
end
|
18
|
+
|
19
|
+
def reset
|
20
|
+
@raise_on_null = true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
class SchemaSerializer
|
2
2
|
class Schema
|
3
|
-
attr_reader :type, :nullable, :items, :required, :properties
|
3
|
+
attr_reader :key, :type, :nullable, :items, :required, :properties
|
4
4
|
|
5
|
-
def initialize(hash = {})
|
5
|
+
def initialize(key, hash = {})
|
6
|
+
@key = key
|
6
7
|
@type = hash["type"]
|
7
8
|
@nullable = !hash["nullable"].nil?
|
8
9
|
|
@@ -18,7 +19,10 @@ class SchemaSerializer
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def serialize(object)
|
21
|
-
|
22
|
+
if object.nil?
|
23
|
+
return nil if nullable
|
24
|
+
raise NullValue, "#{key} is not allowed to be null" if SchemaSerializer.config.raise_on_null
|
25
|
+
end
|
22
26
|
|
23
27
|
case type
|
24
28
|
when "integer"
|
data/lib/schema_serializer.rb
CHANGED
@@ -2,6 +2,7 @@ require "active_support"
|
|
2
2
|
require "active_support/core_ext"
|
3
3
|
require "yaml_ext"
|
4
4
|
|
5
|
+
require "schema_serializer/configuration"
|
5
6
|
require "schema_serializer/definition"
|
6
7
|
require "schema_serializer/schema"
|
7
8
|
require "schema_serializer/serializable"
|
@@ -27,6 +28,10 @@ class SchemaSerializer
|
|
27
28
|
def definition=(define)
|
28
29
|
@definition = define.is_a?(SchemaSerializer::Definition) ? define : SchemaSerializer::Definition.new(define)
|
29
30
|
end
|
31
|
+
|
32
|
+
def config
|
33
|
+
@config ||= Configuration.new
|
34
|
+
end
|
30
35
|
end
|
31
36
|
|
32
37
|
def initialize(object, options = {})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_serializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- i2bskn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-10-
|
11
|
+
date: 2019-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -175,6 +175,7 @@ files:
|
|
175
175
|
- lib/generators/schema_serializer/serializer/serializer_generator.rb
|
176
176
|
- lib/generators/schema_serializer/serializer/templates/serializer.rb.erb
|
177
177
|
- lib/schema_serializer.rb
|
178
|
+
- lib/schema_serializer/configuration.rb
|
178
179
|
- lib/schema_serializer/definition.rb
|
179
180
|
- lib/schema_serializer/errors.rb
|
180
181
|
- lib/schema_serializer/railtie.rb
|