nesquena/rabl — Issue #175: Sequel model instances respond_to :each
Author: scottburton11
Created: 2012-02-25 08:30:28+00:00
State: open

Sequel model instances respond to :each, and thus fail the `is_object?(obj)` test:

helpers.rb
```
# Returns true if obj is not enumerable
# is_object?(@user) => true
# is_object?([]) => false
# is_object?({}) => false
def is_object?(obj)
obj && !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?(:each)
end
```

A typical stack trace looks like this:

```
NoMethodError - undefined method `map' for #:
/Users/scott/.rvm/gems/ruby-1.9.2-p290/gems/rabl-0.5.3/lib/rabl/engine.rb:43:in `to_hash'
/Users/scott/.rvm/gems/ruby-1.9.2-p290/gems/rabl-0.5.3/lib/rabl/engine.rb:53:in `to_json'
/Users/scott/.rvm/gems/ruby-1.9.2-p290/gems/rabl-0.5.3/lib/rabl/engine.rb:28:in `render'
/Users/scott/.rvm/gems/ruby-1.9.2-p290/gems/rabl-0.5.3/lib/rabl/template.rb:15:in `evaluate'
```

Sequel collections unsurprisingly render without error.