ializer 0.10.1 → 0.13.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: 22e363b5f9082ce3f410332d2d64ade84a64fa5411142df02a114442dae11c8f
4
- data.tar.gz: 620228e102aff724fa2e92ffccaed8869b3cb5c8f8aaa11408d37b5d730fa2fb
3
+ metadata.gz: 8576d59eb12dbcbb21750ff9d90e0d3de7f3e1e9df46b70c74924692ecfc22fc
4
+ data.tar.gz: 78cfd59cc6b962793c4f1a5413dc2667a00bd15372243e34e035831f88d898b7
5
5
  SHA512:
6
- metadata.gz: 6afc73be2994f056f271eef6f5961d633b50f3acc0b02e3ca70f2839cf85654d4225ce2a1801cd0d784ad3693d09a71f4b9fa7618d03e0d92d6db2946dde5c62
7
- data.tar.gz: 4a5ea3d806fd72c893a7128dc57ccf22fa916b5bcdb6a275ccec3ba4733a8da05f8af968793289babfafff8b6b24b6345220ef64cfd0fa48375e9f59a3c62d4b
6
+ metadata.gz: 556be5da20a96c4a6d5221e51661321d9c1a79336b5917bf61323262ddd65f56b4f21e134c20ccd36d321ea71fb70399ae1a7f94c913d81401c0bc6e3e5758f7
7
+ data.tar.gz: 7144f7808f6c8a92caa1c3241466f97a8dbb557725e5fc0a0f8d43d4b88e5b0edff648838bfe2c363b9d7f3b2fd2614970a3ba75f596d018f84eea367a857d02
data/README.md CHANGED
@@ -427,6 +427,18 @@ class Customer < De::Ser::Ializer
427
427
  end
428
428
  ```
429
429
 
430
+ Setters can also be overridden:
431
+
432
+ ```ruby
433
+ class Customer < De::Ser::Ializer
434
+ string :name
435
+
436
+ def self.name=(object, value)
437
+ object.name = value.delete_suffix('Part 2')
438
+ end
439
+ end
440
+ ```
441
+
430
442
  Attributes can also use a different name by passing the original method or accessor with a proc shortcut:
431
443
 
432
444
  ```ruby
@@ -52,6 +52,14 @@ module De
52
52
 
53
53
  private
54
54
 
55
+ def add_attribute(field)
56
+ super
57
+
58
+ define_singleton_method field.setter do |object, parsed_value|
59
+ object.public_send(field.setter, parsed_value)
60
+ end
61
+ end
62
+
55
63
  def parse_field(object, field, value)
56
64
  return if value.nil?
57
65
 
@@ -59,7 +67,7 @@ module De
59
67
 
60
68
  return if parsed_value.nil?
61
69
 
62
- object.public_send(field.setter, parsed_value)
70
+ public_send(field.setter, object, parsed_value)
63
71
  end
64
72
 
65
73
  def ostruct?(model_class)
@@ -3,7 +3,7 @@
3
3
  module Ializer
4
4
  class FixNumDeSer
5
5
  def self.serialize(value, _context = nil)
6
- value
6
+ value.to_i
7
7
  end
8
8
 
9
9
  def self.parse(value)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ializer
4
- VERSION = '0.10.1'
4
+ VERSION = '0.13.0'
5
5
  end
@@ -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, :description
14
+ attr_reader :name, :setter, :key, :deser, :model_class, :if_condition, :block, :description, :documentation
15
15
 
16
16
  def initialize(name, options, config, &block)
17
17
  @name = name
@@ -21,6 +21,7 @@ module Ser
21
21
  @if_condition = options[:if]
22
22
  @model_class = options[:model_class]
23
23
  @description = options[:desc]
24
+ @documentation = options[:documentation]
24
25
  @block = block
25
26
  end
26
27
 
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.10.1
4
+ version: 0.13.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: 2022-02-04 00:00:00.000000000 Z
11
+ date: 2022-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -193,7 +193,7 @@ 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.9
196
+ rubygems_version: 3.2.15
197
197
  signing_key:
198
198
  specification_version: 4
199
199
  summary: Simple (de)serializers for Ruby objects