in_json 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/in_json.gemspec +1 -1
- data/lib/in_json/ext/hash.rb +2 -2
- data/lib/in_json.rb +6 -1
- data/spec/in_json_spec.rb +6 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/in_json.gemspec
CHANGED
data/lib/in_json/ext/hash.rb
CHANGED
@@ -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
|
-
|
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