serdes 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +11 -0
- data/lib/serdes/version.rb +1 -1
- data/lib/serdes.rb +10 -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: bc5a0f39e261348c4f4d222f795e09de9dc6f5166d070214b0ffc48ab5615da6
|
4
|
+
data.tar.gz: f0c40e4eb6fec6227754dedb5ab984a87a35e9bbdba1f8dd0e72e77e3a7145fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5607b8aac8a10e6251c530cf39447dd5a9da5754b30b96b5d52f9e87db899085561c2533891183d2d9c3b8137fb22cc29efd69f137c1c19eca569b9fc8f3fe62
|
7
|
+
data.tar.gz: bd25c27df789a9361d9fb8f35cb34dfc14d6181e763682f1af3ed2a18ba52e01aaf482ccdc1b7309b83ae26d404689ea95857b49809d034b28bec90a1c1f7464
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -72,10 +72,21 @@ User.from(user_hash) # => raise Serdes::TypeError
|
|
72
72
|
|
73
73
|
### Macro
|
74
74
|
|
75
|
+
#### Global macro
|
76
|
+
|
75
77
|
- `rename_all_attributes`: Rename all attributes when serializing and deserializing.
|
76
78
|
- Supported: `:snake_case`, `:PascalCase`
|
77
79
|
- `symbolize_all_keys`: Symbolize all keys when serializing and deserializing Hash, and vice versa.
|
78
80
|
|
81
|
+
#### Attribute macro
|
82
|
+
|
83
|
+
You can also use macro for each attribute by specifying 3rd argument of `attribute`.
|
84
|
+
|
85
|
+
- `only`: Only allow given values.
|
86
|
+
- `skip_serializing`: Skip serializing attribute by setting truthy value. it will ignore `skip_serializing_if`, `skip_serializing_if_nil` when this set.
|
87
|
+
- `skip_serializing_if`: Skip serializing if given proc call returns true.
|
88
|
+
- `skip_serializing_if_nil`: alias of `skip_serializing_if: ->(v) { v.nil? }`. It will ignore `skip_serializing_if` when this set.
|
89
|
+
|
79
90
|
## Development
|
80
91
|
|
81
92
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/serdes/version.rb
CHANGED
data/lib/serdes.rb
CHANGED
@@ -102,6 +102,11 @@ module Serdes
|
|
102
102
|
@name = name
|
103
103
|
@attr_type = attr_type
|
104
104
|
@options = options
|
105
|
+
|
106
|
+
if @options[:skip_serializing_if_nil]
|
107
|
+
@options.delete(:skip_serializing_if_nil)
|
108
|
+
@options[:skip_serializing_if] = ->(v) { v.nil? }
|
109
|
+
end
|
105
110
|
end
|
106
111
|
|
107
112
|
def permit?(value)
|
@@ -214,8 +219,13 @@ module Serdes
|
|
214
219
|
self.class.__send__(:_serde_attrs).each_with_object({}) do |(name, attr), hash|
|
215
220
|
key = attr.serialized_name(self.class.__send__(:_serde_rename_strategy))
|
216
221
|
key = key.to_sym if self.class.__send__(:_serde_symbolized_all_keys)
|
222
|
+
|
223
|
+
next if attr.options[:skip_serializing]
|
224
|
+
|
217
225
|
value = __send__(name)
|
218
226
|
|
227
|
+
next if attr.options[:skip_serializing_if] && attr.options[:skip_serializing_if].call(value)
|
228
|
+
|
219
229
|
hash[key] =
|
220
230
|
if value.respond_to?(:to_hash)
|
221
231
|
value.to_hash
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serdes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shia
|
8
8
|
bindir: bin
|
9
9
|
cert_chain: []
|
10
|
-
date: 2025-02
|
10
|
+
date: 2025-03-02 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: Serdes is a tool for serializing and deserializing class.
|
13
13
|
email:
|