in_json 0.0.4 → 0.0.5

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.4
1
+ 0.0.5
data/in_json.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{in_json}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
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"]
@@ -5,10 +5,10 @@ module InJson
5
5
  end
6
6
 
7
7
  module InstanceMethods
8
- def recursively_reject(&blk)
8
+ def recursively_reject(default = nil, &blk)
9
9
  reject(&blk).inject({}) do |result, k_v|
10
10
  key, value = k_v
11
- result[key] = value.is_a?(Hash) ? value.recursively_reject(&blk) : value
11
+ result[key] = value.is_a?(Hash) ? value.recursively_reject(&blk) : (value || default)
12
12
  result
13
13
  end
14
14
  end
data/lib/in_json.rb CHANGED
@@ -65,7 +65,12 @@ module InJson
65
65
  definitions = read_inheritable_attribute(:in_json_definitions) || {}
66
66
  definition = definitions[name]
67
67
  return unless definition
68
- definition.recursively_reject { |key, value| value.nil? }
68
+
69
+ reflexions = reflections
70
+
71
+ definition.recursively_reject({}) { |key, value|
72
+ !(reflexions && reflexions.respond_to?(:has_key?) && reflexions.has_key?(key)) && value.nil?
73
+ }
69
74
  end
70
75
  end
71
76
 
data/spec/in_json_spec.rb CHANGED
@@ -63,7 +63,7 @@ class User < ActiveRecord::Base
63
63
  comments :only_approved
64
64
  end
65
65
  end
66
-
66
+
67
67
  in_json(:with_posts_and_comments_missing) do
68
68
  posts do
69
69
  title
@@ -220,7 +220,7 @@ describe InJson do
220
220
  ]
221
221
  }
222
222
  end
223
-
223
+
224
224
  it "should return model in json with posts and comments missing" do
225
225
  @user.in_json(:with_posts_and_comments_missing).should == {
226
226
  :posts => [
@@ -269,6 +269,10 @@ describe InJson do
269
269
  :comments => {}
270
270
  }
271
271
  }
272
+
273
+ User.include_in_json(:with_posts).should == {
274
+ :posts => {}
275
+ }
272
276
  end
273
277
 
274
278
  it "should use calculated eager-loading includes" do
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Henry Hsu