ializer 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/lib/ializer/version.rb +1 -1
- data/lib/ser/ializer.rb +8 -14
- data/lib/ser/ializer/field.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 23ed07c07fd66ea5e3e8a7fdf7b5704264b1d030d7bf80a8146ae198d97f6ff4
|
4
|
+
data.tar.gz: 64252cc08dd94f2f7655f0889c44e6e8302b16644b178207b4a1c00cfec8ffa3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a8f637568a675eb6889c14d9ecb0874a633572fbb076326ae9f283f89c53e1720d89a595cb37c7f965c8c9699c3f8f2dec80a28162c140e21f57d3b71d56bba
|
7
|
+
data.tar.gz: 7602fa5387d2230097bdfc844d746742702f7f4032b8f9bfaf1ba2c4a545b51b798f85798be94acce7cb97ccde401f420154f82e9ee99cb3ae6e2aa21e74b08c
|
data/README.md
CHANGED
@@ -504,21 +504,30 @@ class UserDeSer < De::Ser::Ializer
|
|
504
504
|
end
|
505
505
|
```
|
506
506
|
|
507
|
-
**Note:**
|
507
|
+
**Note:** Including a deser using `with` will include any method overrides.
|
508
508
|
|
509
509
|
```ruby
|
510
510
|
class BaseApiDeSer < De::Ser::Ializer
|
511
511
|
integer :id
|
512
512
|
timestamp :created_at
|
513
|
+
timestamp :updated_at
|
513
514
|
|
514
515
|
def self.created_at(object, context)
|
515
|
-
#
|
516
|
+
# INCLUDED IN UserDeSer
|
517
|
+
end
|
518
|
+
|
519
|
+
def self.updated_at(object, context)
|
520
|
+
# NOT INCLUDED IN UserDeSer(Overridden below)
|
516
521
|
end
|
517
522
|
end
|
518
523
|
|
519
524
|
class UserDeSer < De::Ser::Ializer
|
520
525
|
with BaseApiDeSer
|
521
526
|
string :email
|
527
|
+
|
528
|
+
def self.updated_at(object, context)
|
529
|
+
# INCLUDED IN UserDeSer.
|
530
|
+
end
|
522
531
|
end
|
523
532
|
```
|
524
533
|
|
data/lib/ializer/version.rb
CHANGED
data/lib/ser/ializer.rb
CHANGED
@@ -29,7 +29,9 @@ 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
|
|
@@ -107,26 +109,18 @@ module Ser
|
|
107
109
|
def add_attribute(field)
|
108
110
|
_attributes[field.key] = field
|
109
111
|
|
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
112
|
define_singleton_method field.name do |object, context|
|
119
|
-
value = field.
|
113
|
+
value = field.get_value(object, context)
|
120
114
|
|
121
115
|
serialize_field(field, value, context)
|
122
116
|
end
|
123
117
|
end
|
124
118
|
|
125
|
-
def
|
126
|
-
|
127
|
-
value = object.public_send(field.name)
|
119
|
+
def add_composed_attribute(field, deser)
|
120
|
+
_attributes[field.key] = field
|
128
121
|
|
129
|
-
|
122
|
+
define_singleton_method field.name do |object, context|
|
123
|
+
deser.public_send(field.name, object, context)
|
130
124
|
end
|
131
125
|
end
|
132
126
|
|
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.3.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-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|