serialize_with_options 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,28 +1,30 @@
1
1
  module SerializeWithOptions
2
+ def self.extended(base)
3
+ base.class_attribute :serialization_conf
4
+ base.class_attribute :serialization_opts
5
+ end
2
6
 
3
7
  def serialize_with_options(set = :default, &block)
4
- configuration = read_inheritable_attribute(:configuration) || {}
5
- options = read_inheritable_attribute(:options) || {}
8
+ conf = self.serialization_conf || {}
9
+ opts = self.serialization_opts || {}
6
10
 
7
- configuration[set] = Config.new.instance_eval(&block)
11
+ conf[set] = Config.new.instance_eval(&block)
8
12
 
9
- write_inheritable_attribute :configuration, configuration
10
- write_inheritable_attribute :options, options
13
+ self.serialization_conf = conf
14
+ self.serialization_opts = opts
11
15
 
12
16
  include InstanceMethods
13
17
  end
14
18
 
15
19
  def serialization_configuration(set)
16
- configuration = read_inheritable_attribute(:configuration)
17
- conf = if configuration
18
- configuration[set] || configuration[:default]
19
- end
20
-
20
+ conf = self.serialization_conf
21
+ conf &&= conf[set] || conf[:default]
21
22
  conf.try(:dup) || { :methods => nil, :only => nil, :except => nil }
22
23
  end
23
24
 
24
25
  def serialization_options(set)
25
- options = read_inheritable_attribute(:options)
26
+ options = self.serialization_opts
27
+
26
28
  options[set] ||= serialization_configuration(set).tap do |opts|
27
29
  includes = opts.delete(:includes)
28
30
 
@@ -43,7 +45,8 @@ module SerializeWithOptions
43
45
  end
44
46
  end
45
47
  end
46
- write_inheritable_attribute :options, options
48
+
49
+ self.serialization_opts = options
47
50
  options[set]
48
51
  end
49
52
 
@@ -1,3 +1,3 @@
1
1
  module SerializeWithOptions
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency "activerecord", "~> 2.3"
22
+ s.add_dependency "activerecord", "~> 3"
23
23
 
24
24
  s.add_development_dependency "shoulda"
25
25
  s.add_development_dependency "sqlite3"
@@ -187,9 +187,9 @@ class SerializeWithOptionsTest < Test::Unit::TestCase
187
187
 
188
188
  context "being converted to JSON" do
189
189
  setup do
190
- @user_hash = JSON.parse(@user.to_json)
191
- @post_hash = JSON.parse(@post.to_json)
192
- @blog_post_hash = JSON.parse(@blog_post.to_json)
190
+ @user_hash = JSON.parse(@user.to_json)["user"]
191
+ @post_hash = JSON.parse(@post.to_json)["post"]
192
+ @blog_post_hash = JSON.parse(@blog_post.to_json)["blog_post"]
193
193
  end
194
194
 
195
195
  should_serialize_with_options
@@ -202,7 +202,7 @@ class SerializeWithOptionsTest < Test::Unit::TestCase
202
202
  end
203
203
 
204
204
  should "find associations with multi-word names" do
205
- user_hash = JSON.parse(@user.to_json(:with_check_ins))
205
+ user_hash = JSON.parse(@user.to_json(:with_check_ins))["user"]
206
206
  assert_equal @check_in.code_name, user_hash['check_ins'].first['code_name']
207
207
  end
208
208
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serialize_with_options
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,18 +14,18 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activerecord
17
- requirement: &2157490520 !ruby/object:Gem::Requirement
17
+ requirement: &2153419300 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
21
21
  - !ruby/object:Gem::Version
22
- version: '2.3'
22
+ version: '3'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2157490520
25
+ version_requirements: *2153419300
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: shoulda
28
- requirement: &2157490100 !ruby/object:Gem::Requirement
28
+ requirement: &2153418880 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2157490100
36
+ version_requirements: *2153418880
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: sqlite3
39
- requirement: &2157489640 !ruby/object:Gem::Requirement
39
+ requirement: &2153418420 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2157489640
47
+ version_requirements: *2153418420
48
48
  description: Simple XML and JSON APIs for your Rails app
49
49
  email:
50
50
  - david.eisinger@gmail.com