serdes 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +1 -0
- data/lib/serdes/version.rb +1 -1
- data/lib/serdes.rb +18 -18
- 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
@@ -30,7 +30,11 @@ module Serdes
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def permit?(value)
|
33
|
-
@exact_type ==
|
33
|
+
if @exact_type == Boolean
|
34
|
+
value == true || value == false
|
35
|
+
else
|
36
|
+
@exact_type == value.class
|
37
|
+
end
|
34
38
|
end
|
35
39
|
|
36
40
|
def to_s
|
@@ -100,6 +104,18 @@ module Serdes
|
|
100
104
|
@options = options
|
101
105
|
end
|
102
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
|
+
|
103
119
|
def serialized_name(rename_strategy = nil)
|
104
120
|
if rename_strategy && rename_strategy != :snake_case
|
105
121
|
Functions._serde_rename_strategy_func_fetch(:snake_case, rename_strategy).call(@name)
|
@@ -262,27 +278,11 @@ module Serdes
|
|
262
278
|
end
|
263
279
|
|
264
280
|
def validate_type!(attr, value)
|
265
|
-
|
266
|
-
return if valid
|
267
|
-
|
268
|
-
actual_type = humanize_type(value)
|
281
|
+
return if attr.permit?(value)
|
269
282
|
|
270
283
|
raise TypeError, "Wrong type for #{attr.class_name}##{attr.name}. Expected type #{attr.attr_type}, got #{value.class} (val: '#{value}')."
|
271
284
|
end
|
272
285
|
|
273
|
-
def humanize_type(value)
|
274
|
-
if value.is_a?(Array)
|
275
|
-
"array(" + value.map { |el| humanize_type(el) }.join(", ") + ")"
|
276
|
-
else
|
277
|
-
case value
|
278
|
-
when NilClass then "nil"
|
279
|
-
when TrueClass then "boolean"
|
280
|
-
when FalseClass then "boolean"
|
281
|
-
else value.class.to_s
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
286
|
def skip_to_hash?(value)
|
287
287
|
case value
|
288
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:
|