in_json 0.0.1 → 0.0.2

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/in_json.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{in_json}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Henry Hsu"]
12
- s.date = %q{2011-03-10}
12
+ s.date = %q{2011-03-11}
13
13
  s.description = %q{JSON serialization for Rails. Straight-forward attributes. Only serialize what you want. Optimally obeys eager-loaded associations}
14
14
  s.email = %q{henry.hsu@photomugs.com}
15
15
  s.extra_rdoc_files = [
data/lib/in_json.rb CHANGED
@@ -81,14 +81,16 @@ module InJson
81
81
  protected
82
82
 
83
83
  def in_json_definition(name, injected_definition)
84
- definitions = self.class.read_inheritable_attribute(:in_json_definitions)
85
- if Thread.current[:in_json_definition] || injected_definition.kind_of?(Symbol)
86
- definitions && (definitions[Thread.current[:in_json_definition]] || definitions[injected_definition])
87
- elsif injected_definition.kind_of?(Hash)
88
- injected_definition
89
- elsif definitions
90
- definitions[name]
91
- end || (definitions && definitions[:default])
84
+ definitions = self.class.read_inheritable_attribute(:in_json_definitions)
85
+ thread_definition = Thread.current[:in_json_definition]
86
+ thread_definition && definitions && result = definitions[thread_definition]
87
+ return result if result # *yuck*
88
+ injected_definition.kind_of?(Symbol) && definitions && result = definitions[injected_definition]
89
+ return result if result
90
+ return injected_definition if injected_definition.kind_of?(Hash)
91
+ definitions && result = definitions[name]
92
+ return result if result
93
+ return definitions && definitions[:default]
92
94
  end
93
95
  end
94
96
  end
data/spec/in_json_spec.rb CHANGED
@@ -4,6 +4,9 @@ class User < ActiveRecord::Base
4
4
  has_many :posts
5
5
  has_many :blog_posts
6
6
 
7
+ # =================================================================================================
8
+ # = All these examples need restructuring to be more direct in what functionality they're testing =
9
+ # =================================================================================================
7
10
  in_json do
8
11
  name
9
12
  email
@@ -296,6 +299,17 @@ describe InJson do
296
299
  end
297
300
  end
298
301
 
302
+ it "should return model in json with posts and comments named via Thread" do
303
+ InJson.with(:with_posts_and_comments_named) do
304
+ @user.in_json.should == {
305
+ :posts => [
306
+ { :title => 'Hello World!', :comments=>[{:approved=>true}] },
307
+ { :title => 'Hello World!', :comments=>[] }
308
+ ]
309
+ }
310
+ end
311
+ end
312
+
299
313
  it "should return model with user" do
300
314
  @post.in_json(:with_user).should == {
301
315
  :user => {
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: in_json
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Henry Hsu
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-10 00:00:00 -08:00
18
+ date: 2011-03-11 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency