lostisland / sawyer

Secret User Agent of HTTP
MIT License
247 stars 75 forks source link

fix deserialization problem #26

Closed huaoguo closed 10 years ago

huaoguo commented 10 years ago

the Sawyer::Resource has serialization problem, for example: Rails.cache.write the instance of Resource class, then I read it from the cache, when i invoke the resource's method, it will raise Error, like 'dont have attr_accessor for nil class', or another error about nil class. I check the source code, and found when deserialization the resource instance, it's @_metaclass didn't initialize -- it was nil, this cause the problem. So I changed @_metaclass to a method, and the problem resolved.

frank-west-iii commented 10 years ago

I just ran into this error today. I have not looked closely at the cause and solution, but +1 for merging this if it corrects the problem.

mgold commented 10 years ago

I also ran across this, and I'm currently monkey patching it myself. LostIsland seems AWOL, and given that GitHub built Octokit.rb on this (that's why we're all here, right?) they really should take it under custody. Otherwise, maybe the three of us?

Software maintenance aside, there's a simpler implementation: just use singleton_class, defined on Object since 1.9.2. (The singleton class is the same as the metaclass and not the same as the singleton design pattern; if this is new to you I recommend Russ Olsen's Eloquent Ruby, chapter 13.)

pengwynn commented 10 years ago

@huaoguo Thanks for tracking it down. We'd be happy to accept a patch. Could you provide tests to make sure this fixes the problem and omit the changes to the .gitignore?

frank-west-iii commented 10 years ago

@pengwynn, does this seems solved and tested in a more appropriate place in pull request #20 written by @dasch?

pengwynn commented 10 years ago

@frank-west-iii indeed. Thanks. :cake: