serdes 0.1.2 → 0.1.3
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 +1 -0
- data/lib/serdes/version.rb +1 -1
- data/lib/serdes.rb +13 -17
- 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: 00cf00141d9d3b1ed522f32261e653b73a7cd0dea98654974bc4e08844474c3b
|
4
|
+
data.tar.gz: ee2953c0dd44a798eb9ee2bb61e0b7652ed4f1a3d4d24ab3897159b12ef51fca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 354f6647e6323ccd23967429d07649da43ddcde185fcbe8a5f9503c4d319096f10cc43784d91da78a4734ec4f368e57e19b29fa59dc7a4fb52f110092e14763a
|
7
|
+
data.tar.gz: bbf2db71e91a585a89a06ccaff47fa050e688ec9af9048c1d042e60d4e9cfe671f6ca42deb396786de18495d5d76022d2555ecf8fe76e42734e3c20178d4f951
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/lib/serdes/version.rb
CHANGED
data/lib/serdes.rb
CHANGED
@@ -104,6 +104,18 @@ module Serdes
|
|
104
104
|
@options = options
|
105
105
|
end
|
106
106
|
|
107
|
+
def permit?(value)
|
108
|
+
return false if !attr_type.permit?(value)
|
109
|
+
|
110
|
+
return true if @options[:only].nil?
|
111
|
+
|
112
|
+
if @options[:only].include?(value)
|
113
|
+
true
|
114
|
+
else
|
115
|
+
raise TypeError, "Wrong value for #{class_name}##{name}. Expected value is #{@options[:only]}, got '#{value}'."
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
107
119
|
def serialized_name(rename_strategy = nil)
|
108
120
|
if rename_strategy && rename_strategy != :snake_case
|
109
121
|
Functions._serde_rename_strategy_func_fetch(:snake_case, rename_strategy).call(@name)
|
@@ -266,27 +278,11 @@ module Serdes
|
|
266
278
|
end
|
267
279
|
|
268
280
|
def validate_type!(attr, value)
|
269
|
-
|
270
|
-
return if valid
|
271
|
-
|
272
|
-
actual_type = humanize_type(value)
|
281
|
+
return if attr.permit?(value)
|
273
282
|
|
274
283
|
raise TypeError, "Wrong type for #{attr.class_name}##{attr.name}. Expected type #{attr.attr_type}, got #{value.class} (val: '#{value}')."
|
275
284
|
end
|
276
285
|
|
277
|
-
def humanize_type(value)
|
278
|
-
if value.is_a?(Array)
|
279
|
-
"array(" + value.map { |el| humanize_type(el) }.join(", ") + ")"
|
280
|
-
else
|
281
|
-
case value
|
282
|
-
when NilClass then "nil"
|
283
|
-
when TrueClass then "boolean"
|
284
|
-
when FalseClass then "boolean"
|
285
|
-
else value.class.to_s
|
286
|
-
end
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
286
|
def skip_to_hash?(value)
|
291
287
|
case value
|
292
288
|
when NilClass, String, Numeric, TrueClass, FalseClass
|
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.3
|
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-02-12 00:00:00.000000000 Z
|
11
11
|
dependencies: []
|
12
12
|
description: Serdes is a tool for serializing and deserializing class.
|
13
13
|
email:
|