rabl 0.8.4 → 0.8.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/.travis.yml +1 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -0
- data/Gemfile.ci +2 -1
- data/lib/rabl/builder.rb +1 -1
- data/lib/rabl/version.rb +1 -1
- data/test/engine_test.rb +25 -0
- metadata +4 -4
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.ci
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in rabl.gemspec
|
4
4
|
gemspec
|
@@ -8,6 +8,7 @@ gem "i18n", '~> 0.6'
|
|
8
8
|
|
9
9
|
platforms :mri_18 do
|
10
10
|
gem 'SystemTimer'
|
11
|
+
gem 'json'
|
11
12
|
end
|
12
13
|
|
13
14
|
gem 'activesupport', :require => 'active_support'
|
data/lib/rabl/builder.rb
CHANGED
@@ -100,7 +100,7 @@ module Rabl
|
|
100
100
|
def child(data, options={}, &block)
|
101
101
|
return false unless data.present? && resolve_condition(options)
|
102
102
|
name, object = data_name(data), data_object(data)
|
103
|
-
include_root = is_collection?(object) && @options[:child_root] # child @users
|
103
|
+
include_root = is_collection?(object) && options.fetch(:object_root, @options[:child_root]) # child @users
|
104
104
|
engine_options = @options.slice(:child_root).merge(:root => include_root)
|
105
105
|
object = { object => name } if data.respond_to?(:each_pair) && object # child :users => :people
|
106
106
|
@_result[name] = self.object_to_hash(object, engine_options, &block)
|
data/lib/rabl/version.rb
CHANGED
data/test/engine_test.rb
CHANGED
@@ -280,6 +280,31 @@ context "Rabl::Engine" do
|
|
280
280
|
scope.instance_variable_set :@user, User.new(:name => 'leo')
|
281
281
|
template.render(scope)
|
282
282
|
end.equals "{\"user\":{\"person\":{\"name\":\"leo\"}}}"
|
283
|
+
|
284
|
+
asserts "it sets root node for child collection" do
|
285
|
+
template = rabl %{
|
286
|
+
object @user
|
287
|
+
attribute :name
|
288
|
+
child(@users) { attribute :city }
|
289
|
+
}
|
290
|
+
scope = Object.new
|
291
|
+
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
|
292
|
+
scope.instance_variable_set :@users, [User.new(:name => 'one', :city => 'UNO'), User.new(:name => 'two', :city => 'DOS')]
|
293
|
+
template.render(scope)
|
294
|
+
end.equals "{\"user\":{\"name\":\"leo\",\"users\":[{\"user\":{\"city\":\"UNO\"}},{\"user\":{\"city\":\"DOS\"}}]}}"
|
295
|
+
|
296
|
+
asserts "it allows suppression of root node for child collection" do
|
297
|
+
template = rabl %{
|
298
|
+
object @user
|
299
|
+
attribute :name
|
300
|
+
child(@users, :object_root => false) { attribute :city }
|
301
|
+
}
|
302
|
+
scope = Object.new
|
303
|
+
scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
|
304
|
+
scope.instance_variable_set :@users, [User.new(:name => 'one', :city => 'UNO'), User.new(:name => 'two', :city => 'DOS')]
|
305
|
+
template.render(scope)
|
306
|
+
end.equals "{\"user\":{\"name\":\"leo\",\"users\":[{\"city\":\"UNO\"},{\"city\":\"DOS\"}]}}"
|
307
|
+
|
283
308
|
end
|
284
309
|
|
285
310
|
context "#glue" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rabl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -421,7 +421,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
421
421
|
version: '0'
|
422
422
|
segments:
|
423
423
|
- 0
|
424
|
-
hash:
|
424
|
+
hash: -2073633213331132502
|
425
425
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
426
426
|
none: false
|
427
427
|
requirements:
|
@@ -430,7 +430,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
430
430
|
version: '0'
|
431
431
|
segments:
|
432
432
|
- 0
|
433
|
-
hash:
|
433
|
+
hash: -2073633213331132502
|
434
434
|
requirements: []
|
435
435
|
rubyforge_project: rabl
|
436
436
|
rubygems_version: 1.8.25
|