super_serialize 0.0.3 → 0.0.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/lib/super_serialize/version.rb +1 -1
- data/lib/super_serialize.rb +12 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 643b5a34abc544e4a27c77af7679a6243746dc4e
|
4
|
+
data.tar.gz: 20bb2ef4df1ffa1bb82c32cf7274aeb3e82d507c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d6aff682824fd655df8108ef2d25c3ba2c5a6a3b06989721313f3cd2f2e227265c72f823a7a49219a98259feb2906598814944cc27ed53ae4a77058f6a6efd3b
|
7
|
+
data.tar.gz: 9334bcde876cf0b1b2b097312edd10a11a04cbe76d8d22f5720b8f37cfe8e6cb72c404025e870c8d0aa59c4b63c1384437452e8e3b7b140297c73562a5bf3708
|
data/lib/super_serialize.rb
CHANGED
@@ -75,7 +75,7 @@ module SuperSerialize
|
|
75
75
|
def #{attr_name}
|
76
76
|
value = super
|
77
77
|
return value.with_indifferent_access if value.is_a?(Hash)
|
78
|
-
return value unless
|
78
|
+
return value unless should_return_loaded_yaml?(value)
|
79
79
|
|
80
80
|
object = YAML::load(value)
|
81
81
|
object.is_a?(Hash) ? object.with_indifferent_access : object
|
@@ -90,6 +90,8 @@ module SuperSerialize
|
|
90
90
|
|
91
91
|
if trying_to_serialize_a_hash?(value)
|
92
92
|
value = attempt_to_sanitize_hash_syntax(value)
|
93
|
+
elsif is_number_string_starting_with_zero?(value)
|
94
|
+
value = value.to_yaml
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
@@ -160,6 +162,15 @@ module SuperSerialize
|
|
160
162
|
end
|
161
163
|
end
|
162
164
|
|
165
|
+
def should_return_loaded_yaml?(value)
|
166
|
+
return false if is_number_string_starting_with_zero?(value)
|
167
|
+
is_valid_yaml?(value)
|
168
|
+
end
|
169
|
+
|
170
|
+
def is_number_string_starting_with_zero?(value)
|
171
|
+
!!(value =~ /^0\d+\.*\d*$/)
|
172
|
+
end
|
173
|
+
|
163
174
|
def trying_to_serialize_a_hash?(value)
|
164
175
|
return false unless value.is_a?(String)
|
165
176
|
!!(value =~ /^{.+}$/)
|