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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01786a69a2421f173b5caaca4c5545f94b6c6762
4
- data.tar.gz: 3b1052d17f4d938cbd1b623458bbeb686ff343fa
3
+ metadata.gz: 113e73578c6129d5fe83f8891462fe48420e0ccb
4
+ data.tar.gz: c5d8288544248745501069722553aa199b50c1c9
5
5
  SHA512:
6
- metadata.gz: 8fe2507216bd560c8ce8bad1e7c1f9fedaf555c047d43825e502abbea5c8287f9b06b8a2c01bcf4d3233481e4aa73bd39f21e39adcedde2f9b94128ca166789e
7
- data.tar.gz: dbe429d9ae48bf5700e121088bf87ab8300262d7112ce0ed4fa08703b9acdee89005ef35251a418bfdc36160c7213357eb9164ff622fee17868c3c74752113b2
6
+ metadata.gz: 0da355d407dd48d5c268364161a2c273710065125157eeb4aaae711a36c6d77b2844138beff05a8ca6efff248d030ca22c7257bfb6a0e76bcfa072f4f4b6cbe0
7
+ data.tar.gz: 823ba318be5d3a2d26085e127e4d4c840c88deb0d0652a1b7e63652afdc2a8e6f133fabc3a72a071321d694259da275a260b8054326a7ca61d9b3cfc545c0926
@@ -1,3 +1,3 @@
1
1
  module SuperSerialize
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -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 is_number_string_starting_with_zero?(value)
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 is_number_string_starting_with_zero?(value)
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 is_number_string_starting_with_zero?(value)
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.6
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-03 00:00:00.000000000 Z
11
+ date: 2015-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails