Permalink
Browse files

Adds better collection detection

  • Loading branch information...
1 parent b1d9e8d commit ee6b89a1ad305adcde92537ec3a78a84fa062c7e @nesquena committed May 22, 2012
Showing with 7 additions and 3 deletions.
  1. +4 −0 CHANGELOG.md
  2. +3 −3 lib/rabl/helpers.rb
View
4 CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG
+## 0.6.13 (Unreleased)
+
+ * Small tweak to is_collection detection (look for each and map)
+
## 0.6.12
* Fix view_path options for renderer (Thanks @ivanvanderbyl and @route)
View
6 lib/rabl/helpers.rb
@@ -50,17 +50,17 @@ def determine_object_root(data, include_root=true)
end
end
- # Returns true if obj is not enumerable
+ # Returns true if obj is not a collection
# is_object?(@user) => true
# is_object?([]) => false
# is_object?({}) => false
def is_object?(obj)
- obj && !data_object(obj).respond_to?(:map)
+ obj && (!data_object(obj).respond_to?(:map) || !data_object(obj).respond_to?(:each))
end
# Returns true if the obj is a collection of items
def is_collection?(obj)
- obj && data_object(obj).respond_to?(:map)
+ obj && data_object(obj).respond_to?(:map) && data_object(obj).respond_to?(:each)
end
# Returns the scope wrapping this engine, used for retrieving data, invoking methods, etc

1 comment on commit ee6b89a

@databyte
Collaborator

👍

Please sign in to comment.