serdes 0.1.4 → 0.1.5
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 -1
- data/lib/serdes/version.rb +1 -1
- data/lib/serdes.rb +23 -3
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 28edbdb79c30f1f680e78f89b179372e2c947f755e192b4fb4e4e1fc1de88815
|
|
4
|
+
data.tar.gz: 61b27b8fa680feefe6d90e217cb26f729c36dcdb4c3703ab2b788824af6ffce1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 57776409c4ebc410ec94d3a07723f280fa029d3f5950dcf132f220e153406cd1eaef2e717249bc691aebf8252de087f051844b27ee974582def946b859d29949
|
|
7
|
+
data.tar.gz: 94a768e64bb467d8acc7fa88184dff9e576d0dfb65600e0f5e95eef2f8c3e58c294d79c4e3ecd3c0a8527bf2c51f8f9dc3905abe1ed4b8a52f4e1a4f50eb5fe5
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -61,7 +61,7 @@ User.from(user_hash) # => raise Serdes::TypeError
|
|
|
61
61
|
- `<class>.from(obj)`: Deserialize object to <class> instance.
|
|
62
62
|
- `from` will call `from_<obj.class>` method if it exists. if not, it returns obj as it is.
|
|
63
63
|
- `<class>#to_hash`: Serialize <class> instance to Hash.
|
|
64
|
-
- There is no support for
|
|
64
|
+
- There is no support for serialization, as only you need to do is just implement `to_<class>` method where you want.
|
|
65
65
|
|
|
66
66
|
### Types
|
|
67
67
|
|
data/lib/serdes/version.rb
CHANGED
data/lib/serdes.rb
CHANGED
|
@@ -107,6 +107,20 @@ module Serdes
|
|
|
107
107
|
@options.delete(:skip_serializing_if_nil)
|
|
108
108
|
@options[:skip_serializing_if] = ->(v) { v.nil? }
|
|
109
109
|
end
|
|
110
|
+
|
|
111
|
+
# Validate default value type if provided
|
|
112
|
+
if @options.key?(:default)
|
|
113
|
+
default_value = @options[:default]
|
|
114
|
+
# Use permit? to validate both type and only constraint
|
|
115
|
+
# permit? will raise TypeError if only constraint is violated
|
|
116
|
+
unless @attr_type.permit?(default_value)
|
|
117
|
+
raise TypeError, "Wrong type for default value of #{class_name}##{name}. Expected type #{@attr_type}, got #{default_value.class} (val: '#{default_value}')."
|
|
118
|
+
end
|
|
119
|
+
# Check only constraint
|
|
120
|
+
if @options[:only] && !@options[:only].include?(default_value)
|
|
121
|
+
raise TypeError, "Wrong value for #{class_name}##{name}. Expected value is #{@options[:only]}, got '#{default_value}'."
|
|
122
|
+
end
|
|
123
|
+
end
|
|
110
124
|
end
|
|
111
125
|
|
|
112
126
|
def permit?(value)
|
|
@@ -188,9 +202,15 @@ module Serdes
|
|
|
188
202
|
key = attr.serialized_name(_serde_rename_strategy)
|
|
189
203
|
key = key.to_sym if _serde_symbolized_all_keys
|
|
190
204
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
205
|
+
if hash.key?(key)
|
|
206
|
+
serialized_value = hash[key]
|
|
207
|
+
value = Functions.from__proxy(attr.attr_type, serialized_value)
|
|
208
|
+
elsif attr.options.key?(:default)
|
|
209
|
+
value = attr.options[:default]
|
|
210
|
+
else
|
|
211
|
+
serialized_value = hash[key]
|
|
212
|
+
value = Functions.from__proxy(attr.attr_type, serialized_value)
|
|
213
|
+
end
|
|
194
214
|
|
|
195
215
|
instance.__send__("#{attr.name}=", value)
|
|
196
216
|
end
|
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.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Shia
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies: []
|
|
12
12
|
description: Serdes is a tool for serializing and deserializing class.
|
|
13
13
|
email:
|
|
@@ -43,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
43
43
|
- !ruby/object:Gem::Version
|
|
44
44
|
version: '0'
|
|
45
45
|
requirements: []
|
|
46
|
-
rubygems_version: 3.6.
|
|
46
|
+
rubygems_version: 3.6.9
|
|
47
47
|
specification_version: 4
|
|
48
48
|
summary: Serdes is a tool for serializing and deserializing class.
|
|
49
49
|
test_files: []
|