ializer 0.1.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rubygems-publish.yml +2 -2
- data/.rubocop.yml +3 -0
- data/README.md +14 -4
- data/ializer.gemspec +2 -1
- data/lib/de/ser/ializer.rb +2 -0
- data/lib/ializer/big_decimal_de_ser.rb +4 -0
- data/lib/ializer/date_de_ser.rb +1 -1
- data/lib/ializer/default_de_ser.rb +1 -0
- data/lib/ializer/millis_de_ser.rb +2 -0
- data/lib/ializer/symbol_de_ser.rb +2 -0
- data/lib/ializer/time_de_ser.rb +2 -0
- data/lib/ializer/version.rb +1 -1
- data/lib/ser/ializer.rb +12 -14
- data/lib/ser/ializer/field.rb +6 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65d2290293ec3f08da6cf2b4b4ce3f30c7240ace2157380f6394c578902f6057
|
4
|
+
data.tar.gz: b7c0e5883f3133c4ea215648af2133cdb8d00153dbd1b53c2a08f3518c62bac7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 14e4e920d24d0a3857dea918cbb318030887c4d5c2ee2c8c27bff61d547fb8c86cc54b573ff142d13c32daf78fbf9efc289d4204d16615cbcee1fbf1b583b5b5
|
7
|
+
data.tar.gz: bfa543caebda04f6bb6ccec07c93bda3b8e57e2f94a63b3221ffa04294467fb88ff9cdbb72ade621450554ff44f103efb932734f81aaa66cc7018cc8b16799d1
|
@@ -22,7 +22,7 @@ jobs:
|
|
22
22
|
mkdir -p $HOME/.gem
|
23
23
|
touch $HOME/.gem/credentials
|
24
24
|
chmod 0600 $HOME/.gem/credentials
|
25
|
-
printf -- "---\n:github: Bearer ${GITHUB_TOKEN}\n:
|
25
|
+
printf -- "---\n:github: Bearer ${GITHUB_TOKEN}\n:rubygems_api_key: Bearer ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
|
26
26
|
env:
|
27
27
|
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
28
28
|
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
|
@@ -36,4 +36,4 @@ jobs:
|
|
36
36
|
- name: Publish to RubyGems
|
37
37
|
run: |
|
38
38
|
gem build *.gemspec
|
39
|
-
gem push --KEY
|
39
|
+
gem push --KEY rubygems_api_key *.gem
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Build](https://github.com/jsteinberg/ializer/workflows/Ruby/badge.svg)](https://github.com/jsteinberg/ializer/actions)
|
1
|
+
[![Build](https://github.com/jsteinberg/ializer/workflows/Ruby/badge.svg)](https://github.com/jsteinberg/ializer/actions) [![Gem Version](https://badge.fury.io/rb/ializer.svg)](https://badge.fury.io/rb/ializer)
|
2
2
|
|
3
3
|
# {De | Ser} Ializer
|
4
4
|
|
@@ -306,9 +306,10 @@ The following types are included with `ializer`
|
|
306
306
|
| String | `string()` | String, :millis |
|
307
307
|
| Symbol | `symbol()` | Symbol, :symbol, :sym |
|
308
308
|
| Time | `timestamp()`| Time, DateTime, :timestamp |
|
309
|
+
| JSON | `json()` | :json |
|
309
310
|
| Default | `default()` | :default |
|
310
311
|
|
311
|
-
**Note: Default just uses the current value of the field and will only properly deserialize if it is a standard json value type(number, string, boolean).**
|
312
|
+
**Note: JSON/Default just uses the current value of the field and will only properly deserialize if it is a standard json value type(number, string, boolean).**
|
312
313
|
|
313
314
|
#### Default Attribute Configuration Options
|
314
315
|
|
@@ -503,21 +504,30 @@ class UserDeSer < De::Ser::Ializer
|
|
503
504
|
end
|
504
505
|
```
|
505
506
|
|
506
|
-
**Note:**
|
507
|
+
**Note:** Including a deser using `with` will include any method overrides.
|
507
508
|
|
508
509
|
```ruby
|
509
510
|
class BaseApiDeSer < De::Ser::Ializer
|
510
511
|
integer :id
|
511
512
|
timestamp :created_at
|
513
|
+
timestamp :updated_at
|
512
514
|
|
513
515
|
def self.created_at(object, context)
|
514
|
-
#
|
516
|
+
# INCLUDED IN UserDeSer
|
517
|
+
end
|
518
|
+
|
519
|
+
def self.updated_at(object, context)
|
520
|
+
# NOT INCLUDED IN UserDeSer(Overridden below)
|
515
521
|
end
|
516
522
|
end
|
517
523
|
|
518
524
|
class UserDeSer < De::Ser::Ializer
|
519
525
|
with BaseApiDeSer
|
520
526
|
string :email
|
527
|
+
|
528
|
+
def self.updated_at(object, context)
|
529
|
+
# INCLUDED IN UserDeSer.
|
530
|
+
end
|
521
531
|
end
|
522
532
|
```
|
523
533
|
|
data/ializer.gemspec
CHANGED
@@ -19,8 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
20
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
21
21
|
spec.require_paths = ['lib']
|
22
|
+
spec.required_ruby_version = '>= 2.4.0'
|
22
23
|
|
23
|
-
spec.add_dependency 'activesupport'
|
24
|
+
spec.add_dependency 'activesupport', '>= 4.0'
|
24
25
|
spec.add_dependency 'multi_json', '~> 1.0'
|
25
26
|
|
26
27
|
spec.add_development_dependency 'bundler'
|
data/lib/de/ser/ializer.rb
CHANGED
@@ -5,10 +5,14 @@ require 'bigdecimal'
|
|
5
5
|
module Ializer
|
6
6
|
class BigDecimalDeSer
|
7
7
|
def self.serialize(value, _context = nil)
|
8
|
+
value = value.to_d unless value.is_a? BigDecimal
|
9
|
+
|
8
10
|
value.to_s('F')
|
9
11
|
end
|
10
12
|
|
11
13
|
def self.parse(value)
|
14
|
+
return nil if value.nil?
|
15
|
+
|
12
16
|
BigDecimal(value)
|
13
17
|
end
|
14
18
|
end
|
data/lib/ializer/date_de_ser.rb
CHANGED
data/lib/ializer/time_de_ser.rb
CHANGED
data/lib/ializer/version.rb
CHANGED
data/lib/ser/ializer.rb
CHANGED
@@ -29,13 +29,17 @@ module Ser
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def with(deser)
|
32
|
-
deser._attributes.values.
|
32
|
+
deser._attributes.values.each do |field|
|
33
|
+
add_composed_attribute(field, deser)
|
34
|
+
end
|
33
35
|
end
|
34
36
|
# End Public DSL
|
35
37
|
|
36
38
|
def serialize(object, context = nil)
|
37
39
|
return serialize_one(object, context) unless valid_enumerable?(object)
|
38
40
|
|
41
|
+
return [] if object.empty?
|
42
|
+
|
39
43
|
object.map { |o| serialize_one(o, context) }
|
40
44
|
end
|
41
45
|
|
@@ -107,26 +111,18 @@ module Ser
|
|
107
111
|
def add_attribute(field)
|
108
112
|
_attributes[field.key] = field
|
109
113
|
|
110
|
-
if field.block
|
111
|
-
add_attribute_with_block(field)
|
112
|
-
else
|
113
|
-
add_attribute_with_method(field)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def add_attribute_with_block(field)
|
118
114
|
define_singleton_method field.name do |object, context|
|
119
|
-
value = field.
|
115
|
+
value = field.get_value(object, context)
|
120
116
|
|
121
117
|
serialize_field(field, value, context)
|
122
118
|
end
|
123
119
|
end
|
124
120
|
|
125
|
-
def
|
126
|
-
|
127
|
-
value = object.public_send(field.name)
|
121
|
+
def add_composed_attribute(field, deser)
|
122
|
+
_attributes[field.key] = field
|
128
123
|
|
129
|
-
|
124
|
+
define_singleton_method field.name do |object, context|
|
125
|
+
deser.public_send(field.name, object, context)
|
130
126
|
end
|
131
127
|
end
|
132
128
|
|
@@ -135,6 +131,8 @@ module Ser
|
|
135
131
|
|
136
132
|
return field.serialize(value, context) unless valid_enumerable?(value)
|
137
133
|
|
134
|
+
return nil if value.empty?
|
135
|
+
|
138
136
|
value.map { |v| field.serialize(v, context) }
|
139
137
|
end
|
140
138
|
|
data/lib/ser/ializer/field.rb
CHANGED
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.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Steinberg
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01
|
11
|
+
date: 2020-06-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
19
|
+
version: '4.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
26
|
+
version: '4.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: multi_json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -186,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
186
186
|
requirements:
|
187
187
|
- - ">="
|
188
188
|
- !ruby/object:Gem::Version
|
189
|
-
version:
|
189
|
+
version: 2.4.0
|
190
190
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - ">="
|