Skip to content
This repository
Browse code

Adds better collection detection

  • Loading branch information...
commit ee6b89a1ad305adcde92537ec3a78a84fa062c7e 1 parent b1d9e8d
Nathan Esquenazi authored

Showing 2 changed files with 7 additions and 3 deletions. Show diff stats Hide diff stats

  1. +4 0 CHANGELOG.md
  2. +3 3 lib/rabl/helpers.rb
4 CHANGELOG.md
Source Rendered
... ... @@ -1,5 +1,9 @@
1 1 # CHANGELOG
2 2
  3 +## 0.6.13 (Unreleased)
  4 +
  5 + * Small tweak to is_collection detection (look for each and map)
  6 +
3 7 ## 0.6.12
4 8
5 9 * Fix view_path options for renderer (Thanks @ivanvanderbyl and @route)
6 lib/rabl/helpers.rb
@@ -50,17 +50,17 @@ def determine_object_root(data, include_root=true)
50 50 end
51 51 end
52 52
53   - # Returns true if obj is not enumerable
  53 + # Returns true if obj is not a collection
54 54 # is_object?(@user) => true
55 55 # is_object?([]) => false
56 56 # is_object?({}) => false
57 57 def is_object?(obj)
58   - obj && !data_object(obj).respond_to?(:map)
  58 + obj && (!data_object(obj).respond_to?(:map) || !data_object(obj).respond_to?(:each))
59 59 end
60 60
61 61 # Returns true if the obj is a collection of items
62 62 def is_collection?(obj)
63   - obj && data_object(obj).respond_to?(:map)
  63 + obj && data_object(obj).respond_to?(:map) && data_object(obj).respond_to?(:each)
64 64 end
65 65
66 66 # Returns the scope wrapping this engine, used for retrieving data, invoking methods, etc

1 comment on commit ee6b89a

David Sommers
Collaborator

:+1:

Please sign in to comment.
Something went wrong with that request. Please try again.