ializer 0.9.1 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ializer.gemspec +2 -2
- data/lib/de/ser/ializer.rb +2 -2
- data/lib/ializer/version.rb +1 -1
- data/lib/ser/ializer/field.rb +2 -1
- data/lib/ser/ializer.rb +22 -15
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22e363b5f9082ce3f410332d2d64ade84a64fa5411142df02a114442dae11c8f
|
4
|
+
data.tar.gz: 620228e102aff724fa2e92ffccaed8869b3cb5c8f8aaa11408d37b5d730fa2fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6afc73be2994f056f271eef6f5961d633b50f3acc0b02e3ca70f2839cf85654d4225ce2a1801cd0d784ad3693d09a71f4b9fa7618d03e0d92d6db2946dde5c62
|
7
|
+
data.tar.gz: 4a5ea3d806fd72c893a7128dc57ccf22fa916b5bcdb6a275ccec3ba4733a8da05f8af968793289babfafff8b6b24b6345220ef64cfd0fa48375e9f59a3c62d4b
|
data/ializer.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'pry'
|
29
29
|
spec.add_development_dependency 'rake'
|
30
30
|
spec.add_development_dependency 'rspec'
|
31
|
-
spec.add_development_dependency 'rubocop', '~>
|
32
|
-
spec.add_development_dependency 'rubocop-rspec'
|
31
|
+
spec.add_development_dependency 'rubocop', '~> 1.19'
|
32
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 2.8'
|
33
33
|
spec.add_development_dependency 'simplecov'
|
34
34
|
end
|
data/lib/de/ser/ializer.rb
CHANGED
@@ -35,7 +35,7 @@ module De
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def parse_attribute(object, key, value)
|
38
|
-
field =
|
38
|
+
field = attributes[key]
|
39
39
|
|
40
40
|
return unless field
|
41
41
|
|
@@ -77,7 +77,7 @@ module De
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def parse_ostruct_field(object, key, value)
|
80
|
-
field =
|
80
|
+
field = attributes[key]
|
81
81
|
|
82
82
|
return unless field
|
83
83
|
|
data/lib/ializer/version.rb
CHANGED
data/lib/ser/ializer/field.rb
CHANGED
@@ -11,7 +11,7 @@ module Ser
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
attr_reader :name, :setter, :key, :deser, :model_class, :if_condition, :block
|
14
|
+
attr_reader :name, :setter, :key, :deser, :model_class, :if_condition, :block, :description
|
15
15
|
|
16
16
|
def initialize(name, options, config, &block)
|
17
17
|
@name = name
|
@@ -20,6 +20,7 @@ module Ser
|
|
20
20
|
@deser = options[:deser]
|
21
21
|
@if_condition = options[:if]
|
22
22
|
@model_class = options[:model_class]
|
23
|
+
@description = options[:desc]
|
23
24
|
@block = block
|
24
25
|
end
|
25
26
|
|
data/lib/ser/ializer.rb
CHANGED
@@ -47,7 +47,7 @@ module Ser
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def with(deser)
|
50
|
-
deser.
|
50
|
+
deser.attributes.each_value do |field|
|
51
51
|
add_composed_attribute(field, deser)
|
52
52
|
end
|
53
53
|
end
|
@@ -76,6 +76,8 @@ module Ser
|
|
76
76
|
matchers.each do |matcher|
|
77
77
|
method_registry[matcher.to_s.to_sym] = method_name
|
78
78
|
end
|
79
|
+
|
80
|
+
deser_types[deser.to_s] = method_name.capitalize
|
79
81
|
end
|
80
82
|
|
81
83
|
def register_default(deser)
|
@@ -89,8 +91,22 @@ module Ser
|
|
89
91
|
end
|
90
92
|
end
|
91
93
|
|
94
|
+
# Maps a registered deser to the value type that it serializes
|
95
|
+
def deser_types
|
96
|
+
@deser_types ||= {}
|
97
|
+
end
|
98
|
+
|
92
99
|
def attribute_names
|
93
|
-
|
100
|
+
attributes.values.map(&:name)
|
101
|
+
end
|
102
|
+
|
103
|
+
def attributes
|
104
|
+
@attributes ||=
|
105
|
+
if equal? Ser::Ializer
|
106
|
+
ActiveSupport::HashWithIndifferentAccess.new
|
107
|
+
else
|
108
|
+
superclass.attributes.dup
|
109
|
+
end
|
94
110
|
end
|
95
111
|
|
96
112
|
protected
|
@@ -111,15 +127,6 @@ module Ser
|
|
111
127
|
method(method_name)
|
112
128
|
end
|
113
129
|
|
114
|
-
def _attributes
|
115
|
-
@attributes ||=
|
116
|
-
if equal? Ser::Ializer
|
117
|
-
ActiveSupport::HashWithIndifferentAccess.new
|
118
|
-
else
|
119
|
-
superclass._attributes.dup
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
130
|
private
|
124
131
|
|
125
132
|
def warning_message(name)
|
@@ -127,7 +134,7 @@ module Ser
|
|
127
134
|
end
|
128
135
|
|
129
136
|
def add_attribute(field)
|
130
|
-
|
137
|
+
attributes[field.key] = field
|
131
138
|
|
132
139
|
define_singleton_method field.name do |object, context|
|
133
140
|
value = field.get_value(object, context)
|
@@ -137,7 +144,7 @@ module Ser
|
|
137
144
|
end
|
138
145
|
|
139
146
|
def add_composed_attribute(field, deser)
|
140
|
-
|
147
|
+
attributes[field.key] = field
|
141
148
|
|
142
149
|
define_singleton_method field.name do |object, context|
|
143
150
|
deser.public_send(field.name, object, context)
|
@@ -169,9 +176,9 @@ module Ser
|
|
169
176
|
def fields_for_serialization(context)
|
170
177
|
field_names = fields_names_for_serialization(context)
|
171
178
|
|
172
|
-
return
|
179
|
+
return attributes.values unless field_names
|
173
180
|
|
174
|
-
|
181
|
+
attributes.values_at(*field_names).compact
|
175
182
|
end
|
176
183
|
|
177
184
|
def fields_names_for_serialization(context)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ializer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Steinberg
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -100,28 +100,28 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: '1.19'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: '1.19'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: rubocop-rspec
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- - "
|
115
|
+
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '2.8'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- - "
|
122
|
+
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '2.8'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: simplecov
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,8 +136,8 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
-
description:
|
140
|
-
email:
|
139
|
+
description:
|
140
|
+
email:
|
141
141
|
executables:
|
142
142
|
- console
|
143
143
|
- setup
|
@@ -178,7 +178,7 @@ homepage: https://github.com/jsteinberg/ializer
|
|
178
178
|
licenses:
|
179
179
|
- MIT
|
180
180
|
metadata: {}
|
181
|
-
post_install_message:
|
181
|
+
post_install_message:
|
182
182
|
rdoc_options: []
|
183
183
|
require_paths:
|
184
184
|
- lib
|
@@ -193,8 +193,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '0'
|
195
195
|
requirements: []
|
196
|
-
rubygems_version: 3.0.
|
197
|
-
signing_key:
|
196
|
+
rubygems_version: 3.0.9
|
197
|
+
signing_key:
|
198
198
|
specification_version: 4
|
199
199
|
summary: Simple (de)serializers for Ruby objects
|
200
200
|
test_files: []
|