serialize_variants 0.1.2 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/Rakefile +1 -1
  2. data/lib/serialize_variants.rb +20 -2
  3. metadata +2 -2
data/Rakefile CHANGED
@@ -34,7 +34,7 @@ PKG_FILES = FileList[
34
34
 
35
35
  spec = Gem::Specification.new do |s|
36
36
  s.name = "serialize_variants"
37
- s.version = "0.1.2"
37
+ s.version = "0.1.8"
38
38
  s.author = "Nicolas Goy"
39
39
  s.email = "kuon@goyman.com"
40
40
  s.homepage = "http://goyman.com/"
@@ -23,12 +23,30 @@ module SerializeVariants
23
23
  force = options[:force] || {}
24
24
 
25
25
  if options[:variant]
26
- super((self.class.serialize_variant(options[:variant]) || {}).merge(force))
26
+ res = super((self.class.serialize_variant(options[:variant]) || {}).merge(options).merge(force))
27
27
  else
28
- super(options)
28
+ res = super(options)
29
+ end
30
+ if options[:delete_blank]
31
+ SerializeVariants::delete_blank(res)
32
+ else
33
+ res
29
34
  end
30
35
  end
36
+
37
+ end
38
+ def self.delete_blank(hash)
39
+ hash.delete_if do |k, v|
40
+ v.compact! if v.respond_to?(:compact!)
41
+ next true if v == nil
42
+ next true if v.respond_to?(:empty?) && v.empty?
43
+ next true if v.instance_of?(Hash) && SerializeVariants::delete_blank(v).empty?
44
+ next false
45
+ end
46
+ hash
31
47
  end
32
48
  end
33
49
 
34
50
  ::ActiveRecord::Base.send :include, SerializeVariants::Variants
51
+
52
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: serialize_variants
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nicolas Goy
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-31 00:00:00 +02:00
13
+ date: 2011-06-23 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies: []
16
16