super_serialize 0.0.6 → 0.0.7
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 +28 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 113e73578c6129d5fe83f8891462fe48420e0ccb
|
4
|
+
data.tar.gz: c5d8288544248745501069722553aa199b50c1c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0da355d407dd48d5c268364161a2c273710065125157eeb4aaae711a36c6d77b2844138beff05a8ca6efff248d030ca22c7257bfb6a0e76bcfa072f4f4b6cbe0
|
7
|
+
data.tar.gz: 823ba318be5d3a2d26085e127e4d4c840c88deb0d0652a1b7e63652afdc2a8e6f133fabc3a72a071321d694259da275a260b8054326a7ca61d9b3cfc545c0926
|
data/lib/super_serialize.rb
CHANGED
@@ -110,7 +110,7 @@ module SuperSerialize
|
|
110
110
|
|
111
111
|
if trying_to_serialize_a_hash?(value)
|
112
112
|
value = attempt_to_sanitize_hash_syntax(value)
|
113
|
-
elsif
|
113
|
+
elsif number_string_starting_with_zero?(value)
|
114
114
|
value = value.to_yaml
|
115
115
|
elsif value == ''
|
116
116
|
value = nil
|
@@ -178,7 +178,7 @@ module SuperSerialize
|
|
178
178
|
|
179
179
|
def is_valid_yaml?(value)
|
180
180
|
begin
|
181
|
-
# YAML::load('') returns false
|
181
|
+
# because YAML::load('') returns false
|
182
182
|
return true if value == ''
|
183
183
|
|
184
184
|
!!YAML.load(value)
|
@@ -188,14 +188,38 @@ module SuperSerialize
|
|
188
188
|
end
|
189
189
|
|
190
190
|
def should_return_loaded_yaml?(value)
|
191
|
-
return false if
|
191
|
+
return false if number_string_starting_with_zero?(value)
|
192
|
+
return false if string_with_colons_and_not_hash_or_yaml?(value)
|
192
193
|
is_valid_yaml?(value)
|
193
194
|
end
|
194
195
|
|
195
|
-
def
|
196
|
+
def number_string_starting_with_zero?(value)
|
196
197
|
!!(value =~ /^0\d+\.*\d*$/)
|
197
198
|
end
|
198
199
|
|
200
|
+
# This is to take care of the following very specific scenario:
|
201
|
+
# > YAML::load("Note: something")
|
202
|
+
# => {"Note"=>"something"}
|
203
|
+
#
|
204
|
+
# This is only an issue when the set value has not been saved to the DB
|
205
|
+
def string_with_colons_and_not_hash_or_yaml?(value)
|
206
|
+
# Value should be a string
|
207
|
+
return false unless value.is_a?(String)
|
208
|
+
|
209
|
+
# Stringified YAML starts with 3 dashes; ensure not already yamilified
|
210
|
+
return false if !!(value =~ /\A---/)
|
211
|
+
|
212
|
+
# Should be trying to serialize a hash
|
213
|
+
return false if trying_to_serialize_a_hash?(value)
|
214
|
+
|
215
|
+
# Should also be valid YAML
|
216
|
+
return false unless is_valid_yaml?(value)
|
217
|
+
|
218
|
+
# Check if the returned, loaded, valid YAML is a Hash.
|
219
|
+
# If so, return string value.
|
220
|
+
YAML::load(value).is_a?(Hash)
|
221
|
+
end
|
222
|
+
|
199
223
|
def trying_to_serialize_a_hash?(value)
|
200
224
|
return false unless value.is_a?(String)
|
201
225
|
!!(value =~ /^{.+}$/)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: super_serialize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Quiñones
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|