serialize_variants 0.0.7 → 0.1.1

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.
Files changed (4) hide show
  1. data/README.md +3 -1
  2. data/Rakefile +1 -1
  3. data/lib/serialize_variants.rb +10 -12
  4. metadata +2 -2
data/README.md CHANGED
@@ -10,11 +10,13 @@ Example
10
10
 
11
11
  In your model file:
12
12
 
13
- short_serialize_options :only => [:id, :name]
13
+ serialize_options :short, :only => [:id, :name]
14
+ serialize_options :long, :except => [:hidden]
14
15
 
15
16
  Anywhere, but typically in your controller file:
16
17
 
17
18
  render :json => my_object.to_json(:variant => :short)
19
+ my_hash = my_object.as_json(:variant => :long)
18
20
 
19
21
 
20
22
 
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.0.7"
37
+ s.version = "0.1.1"
38
38
  s.author = "Nicolas Goy"
39
39
  s.email = "kuon@goyman.com"
40
40
  s.homepage = "http://goyman.com/"
@@ -3,13 +3,13 @@ require "active_record"
3
3
  module SerializeVariants
4
4
  module Variants
5
5
  module ClassMethods
6
- def short_serialize_options(options=nil)
7
- @short_serialize_options = options if options
8
- @short_serialize_options
9
- end
10
- def long_serialize_options(options=nil)
11
- @long_serialize_options = options if options
12
- @long_serialize_options
6
+ def serialize_variant(variant, options=nil)
7
+ @serialize_variant ||= {}
8
+ if options
9
+ options[:variant] = variant
10
+ @serialize_variant[variant] = options
11
+ end
12
+ @serialize_variant[variant]
13
13
  end
14
14
  end
15
15
 
@@ -22,11 +22,9 @@ module SerializeVariants
22
22
  variant = options[:variant]
23
23
  force = options[:force] || {}
24
24
 
25
- case options[:variant]
26
- when :short
27
- super((self.class.short_serialize_options || {}).merge(force))
28
- when :long
29
- super((self.class.long_serialize_options || {}).merge(force))
25
+ if options[:variant]
26
+ puts self.class.serialize_variant(options[:variant])
27
+ super((self.class.serialize_variant(options[:variant]) || {}).merge(force))
30
28
  else
31
29
  super(options)
32
30
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: serialize_variants
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.7
5
+ version: 0.1.1
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-25 00:00:00 +02:00
13
+ date: 2011-05-31 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies: []
16
16