peritor / simply_stored

A convenience wrapper around CouchDB (using CouchPotato) that supports relations and S3 attachments
Other
140 stars 16 forks source link

Exception on comparison with foreign object #5

Closed d5e closed 14 years ago

d5e commented 14 years ago

I ran into this error when I was doing an myarray.include?(:some_symbol)

myarray holds some SimplyStored Documents ... when comparing of those it raises an

undefined method `_id' for :mySymbol:Symbol
/usr/lib/ruby/gems/1.8/gems/simply_stored-0.3.6/lib/simply_stored/instance_methods.rb:11:in `=='

this comes as the equals method (==) does not check whether other is an simply stored object. So any object is asked for its _id-method which of course is not available for objects of foreign classes.

So instead of

def ==(other)
    other._id == _id && other._rev == _rev
end

just do

def ==(other)
    other.kind_of?(SimplyStored::Couch) && other._id == _id && other._rev == _rev
end

and the problem is solved.

jweiss commented 14 years ago

Fixed in http://github.com/peritor/simply_stored/commit/6acef52b5deec28f79ee7d8fca6946f509c1b774

Thanks!