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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ec12881a7736268012824062951ad8a0d0897687798d1215ef3cf100d1022ab4
4
- data.tar.gz: c0793bd033a02cb2cf675c483e1e265bc80e3745290989c1bb652f006058be82
3
+ metadata.gz: 23ed07c07fd66ea5e3e8a7fdf7b5704264b1d030d7bf80a8146ae198d97f6ff4
4
+ data.tar.gz: 64252cc08dd94f2f7655f0889c44e6e8302b16644b178207b4a1c00cfec8ffa3
5
5
  SHA512:
6
- metadata.gz: a314f2d7ee625d7aa92d4756c21a185aa50b152112fc24ea38bba4e56c49de8bdcb032f66bf089f781f0a580bae30078879c6ffaa02fbc869c3c942bb07ef8fd
7
- data.tar.gz: cb08168fb231f03ee45ad1ae429a9a0d79438b546bc4ed71f9132606f522a02af09c70a192a6e61fa8a4c130ac50fd0ded6719ad3857ec147f8fbcd6bad5a93e
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:** Because of scoping, including a deser using `with` will not include any method overrides
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
- # NOT INCLUDED IN UserDeSer. UserDeSer will call `.created_at` on any serialization target
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ializer
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
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.map(&:dup).each(&method(:add_attribute))
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.block.call(object, context)
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 add_attribute_with_method(field)
126
- define_singleton_method field.name do |object, context|
127
- value = object.public_send(field.name)
119
+ def add_composed_attribute(field, deser)
120
+ _attributes[field.key] = field
128
121
 
129
- serialize_field(field, value, context)
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
 
@@ -23,6 +23,12 @@ module Ser
23
23
  @block = block
24
24
  end
25
25
 
26
+ def get_value(object, context)
27
+ return object.public_send(name) unless block
28
+
29
+ block.call(object, context)
30
+ end
31
+
26
32
  def serialize(value, context)
27
33
  deser.serialize(value, context)
28
34
  end
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.2.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-07 00:00:00.000000000 Z
11
+ date: 2020-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport