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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 00cf00141d9d3b1ed522f32261e653b73a7cd0dea98654974bc4e08844474c3b
4
- data.tar.gz: ee2953c0dd44a798eb9ee2bb61e0b7652ed4f1a3d4d24ab3897159b12ef51fca
3
+ metadata.gz: bc5a0f39e261348c4f4d222f795e09de9dc6f5166d070214b0ffc48ab5615da6
4
+ data.tar.gz: f0c40e4eb6fec6227754dedb5ab984a87a35e9bbdba1f8dd0e72e77e3a7145fe
5
5
  SHA512:
6
- metadata.gz: 354f6647e6323ccd23967429d07649da43ddcde185fcbe8a5f9503c4d319096f10cc43784d91da78a4734ec4f368e57e19b29fa59dc7a4fb52f110092e14763a
7
- data.tar.gz: bbf2db71e91a585a89a06ccaff47fa050e688ec9af9048c1d042e60d4e9cfe671f6ca42deb396786de18495d5d76022d2555ecf8fe76e42734e3c20178d4f951
6
+ metadata.gz: 5607b8aac8a10e6251c530cf39447dd5a9da5754b30b96b5d52f9e87db899085561c2533891183d2d9c3b8137fb22cc29efd69f137c1c19eca569b9fc8f3fe62
7
+ data.tar.gz: bd25c27df789a9361d9fb8f35cb34dfc14d6181e763682f1af3ed2a18ba52e01aaf482ccdc1b7309b83ae26d404689ea95857b49809d034b28bec90a1c1f7464
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.4]
4
+
5
+ - Add skip serializing attribute feature.
6
+
3
7
  ## [0.1.3] - 2025-02-12
4
8
 
5
9
  - Add `only` option which adds value constraint.
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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Serdes
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
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.3
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-12 00:00:00.000000000 Z
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: