schema_serializer 0.0.1 → 0.0.2
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 +4 -4
- data/lib/generators/schema_serializer/serializer_generator.rb +9 -0
- data/lib/generators/schema_serializer/templates/serializer.rb.erb +2 -0
- data/lib/schema_serializer.rb +6 -8
- data/lib/schema_serializer/definition.rb +1 -1
- data/lib/schema_serializer/schema.rb +4 -0
- data/lib/schema_serializer/serializable.rb +1 -1
- data/lib/schema_serializer/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5404332ba242848977ad36f8fdb7a10aca0e9075976ccbe03c439de1fe919c5
|
4
|
+
data.tar.gz: c270f0b70fa19a3578cd5a7bf836d29fcbfa2085bad74eb7662a1209d39e3e8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccba07d36a8e858ec0e175d5f7353cc632babe90211e7d50edb5d5a23b9d1e49c25a5c226b2b26b8cd678ec08e1fa80a8a53b3054991d1705af8a5e123657c62
|
7
|
+
data.tar.gz: b704f1f029e65c35769e7c8ab9732acf672514a63b4f123b77ae1abf2899e94861373cd48d259e2f8f3159e3f34cc8ca0de78462a73c695407778cf85ebaef2e
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module SchemaSerializer::Generators
|
2
|
+
class SerializerGenerator < Rails::Generators::NamedBase
|
3
|
+
source_root File.expand_path("templates", __dir__)
|
4
|
+
|
5
|
+
def create_serializer
|
6
|
+
template "serializer.rb.erb", File.join("app/serializers", "#{file_name}_serializer.rb")
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
data/lib/schema_serializer.rb
CHANGED
@@ -22,7 +22,7 @@ class SchemaSerializer
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def initialize(object)
|
25
|
+
def initialize(object, options = {})
|
26
26
|
@object = object
|
27
27
|
end
|
28
28
|
|
@@ -31,11 +31,13 @@ class SchemaSerializer
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def schema
|
34
|
-
self.class.definition.
|
34
|
+
self.class.definition.schema(schema_name)
|
35
35
|
end
|
36
36
|
|
37
37
|
def schema_name
|
38
|
-
|
38
|
+
return self.class.name.sub("Serializer", "") if self.class < SchemaSerializer
|
39
|
+
|
40
|
+
object.class.name
|
39
41
|
end
|
40
42
|
|
41
43
|
private
|
@@ -43,11 +45,7 @@ class SchemaSerializer
|
|
43
45
|
def method_missing(name, *args, &block)
|
44
46
|
super unless object.respond_to?(name)
|
45
47
|
|
46
|
-
|
47
|
-
object.public_send(name)
|
48
|
-
end
|
49
|
-
|
50
|
-
send(name, *args, &block)
|
48
|
+
object.public_send(name, *args, &block)
|
51
49
|
end
|
52
50
|
|
53
51
|
def respond_to_missing?(name, include_private = false)
|
@@ -27,9 +27,13 @@ class SchemaSerializer
|
|
27
27
|
object.to_f
|
28
28
|
when "string"
|
29
29
|
object.to_s
|
30
|
+
when "boolean"
|
31
|
+
!!object
|
30
32
|
when "array"
|
31
33
|
object.map { |item| items.serialize(item) }
|
32
34
|
else
|
35
|
+
not_enough_columns = required - properties.keys
|
36
|
+
raise RequiredNotDefined, not_enough_columns.join(", ") unless not_enough_columns.empty?
|
33
37
|
properties.each_with_object({}) { |(column, schema), obj|
|
34
38
|
obj[column] = schema.serialize(object.public_send(column))
|
35
39
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class SchemaSerializer
|
2
2
|
module Serializable
|
3
3
|
def serializer(klass = nil)
|
4
|
-
(klass || "#{self.class.
|
4
|
+
(klass || "#{self.class.name}Serializer".safe_constantize || SchemaSerializer).new(self)
|
5
5
|
end
|
6
6
|
end
|
7
7
|
end
|
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- i2bskn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -109,6 +109,8 @@ files:
|
|
109
109
|
- Rakefile
|
110
110
|
- bin/console
|
111
111
|
- bin/setup
|
112
|
+
- lib/generators/schema_serializer/serializer_generator.rb
|
113
|
+
- lib/generators/schema_serializer/templates/serializer.rb.erb
|
112
114
|
- lib/schema_serializer.rb
|
113
115
|
- lib/schema_serializer/definition.rb
|
114
116
|
- lib/schema_serializer/definition/from_openapi3_parser.rb
|