rabl 0.5.0 → 0.5.1

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/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 0.5.1 (Unreleased)
3
+ ## 0.5.2 (Unreleased)
4
+
5
+ ## 0.5.1
6
+
7
+ * Use respond\_to? instead of checking Enumerable for is\_object
8
+ * Performance optimization (thanks Eric Allen)
4
9
 
5
10
  ## 0.5.0
6
11
 
data/lib/rabl/engine.rb CHANGED
@@ -34,8 +34,12 @@ module Rabl
34
34
  if is_object?(data) || !data # object @user
35
35
  Rabl::Builder.new(@_data, options).to_hash(options)
36
36
  elsif is_collection?(data) # collection @users
37
- object_name = data_name(@_data).to_s.singularize # @users => :users
38
- data.map { |object| Rabl::Builder.new({ object => object_name }, options).to_hash(options) }
37
+ if options[:root] # only calculate root name if needed
38
+ object_name = data_name(@_data).to_s.singularize # @users => :users
39
+ data.map { |object| Rabl::Builder.new({ object => object_name }, options).to_hash(options) }
40
+ else
41
+ data.map { |object| Rabl::Builder.new(object, options).to_hash(options) }
42
+ end
39
43
  end
40
44
  end
41
45
 
data/lib/rabl/helpers.rb CHANGED
@@ -63,12 +63,12 @@ module Rabl
63
63
  # is_object?([]) => false
64
64
  # is_object?({}) => false
65
65
  def is_object?(obj)
66
- obj && !data_object(obj).is_a?(Enumerable)
66
+ obj && !data_object(obj).respond_to?(:each)
67
67
  end
68
68
 
69
69
  # Returns true if the obj is a collection of items
70
70
  def is_collection?(obj)
71
- obj && data_object(obj).is_a?(Enumerable)
71
+ obj && data_object(obj).respond_to?(:each)
72
72
  end
73
73
 
74
74
  # Returns source for a given relative file
data/lib/rabl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rabl
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
data/test/engine_test.rb CHANGED
@@ -159,6 +159,21 @@ context "Rabl::Engine" do
159
159
  template.render(scope).split('').sort
160
160
  end.equals "[{\"user\":{\"name\":\"a\"}},{\"user\":{\"name\":\"b\"}}]".split('').sort
161
161
 
162
+ asserts "that it can merge the result on a child node given no name" do
163
+ template = rabl %{
164
+ object @user
165
+ attribute :name
166
+ child(@user) do
167
+ code do |user|
168
+ {:city => user.city}
169
+ end
170
+ end
171
+ }
172
+ scope = Object.new
173
+ scope.instance_variable_set :@user, User.new(:name => 'leo', :city => 'LA')
174
+ template.render(scope).split('').sort
175
+ end.equals "{\"user\":{\"name\":\"leo\",\"user\":{\"city\":\"LA\"}}}".split('').sort
176
+
162
177
  end
163
178
 
164
179
  context "#child" do
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rabl
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.0
5
+ version: 0.5.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nathan Esquenazi
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-10-19 00:00:00 Z
13
+ date: 2011-11-06 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: multi_json