Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug in leslie branch: can't handle atomic types #12

Open
joshbronson opened this issue Jan 7, 2014 · 0 comments
Open

bug in leslie branch: can't handle atomic types #12

joshbronson opened this issue Jan 7, 2014 · 0 comments

Comments

@joshbronson
Copy link
Contributor

I meant to fix this, but I got side-tracked. I'm adding this now, since @kornypoet is refactoring some bits of Vayacondios.

As far as I can tell from the doccos, this should work:

>> client = Vayacondios::HttpClient.new(organization: 'icstest')                                                                                                                                                                                                              
=> #<Vayacondios::HttpClient:0x007fb21aafafb8 @options={:organization=>"icstest"}, @organization="icstest", @host="localhost", @port=9000, @headers={"Content-Type"=>"application/json"}, @timeout=30>
>> client.set(topic: 'x', id: 'y', value: {z: 1})
=> {"z"=>1}
>> client.get(topic: 'x', id: 'y.z')
TypeError: can't define singleton
        from /Users/joshbronson/Source/vayacondios/lib/vayacondios/client/http_client.rb:270:in `extend_object'
        from /Users/joshbronson/Source/vayacondios/lib/vayacondios/client/http_client.rb:270:in `extend'
        from /Users/joshbronson/Source/vayacondios/lib/vayacondios/client/http_client.rb:270:in `handle_response'
        from /Users/joshbronson/Source/vayacondios/lib/vayacondios/client/http_client.rb:258:in `block in send_request'
        from /Users/joshbronson/.rbenv/versions/1.9.3-p125/lib/ruby/1.9.1/timeout.rb:68:in `timeout'
        from /Users/joshbronson/Source/vayacondios/lib/vayacondios/client/http_client.rb:257:in `send_request'
        from /Users/joshbronson/Source/vayacondios/lib/vayacondios/client/http_client.rb:124:in `request'
        from /Users/joshbronson/Source/vayacondios/lib/vayacondios/client/http_client.rb:160:in `perform_get'
        from /Users/joshbronson/Source/vayacondios/lib/vayacondios/client/client.rb:319:in `get'
        from (irb):4
        from /Users/joshbronson/.rbenv/versions/1.9.3-p125/bin/irb:12:in `<main>'

and this does work:

>> client.set!(topic: 'x', id: 'y', value: {x: '1'})
=> {"x"=>"1"}
>> client.get(topic: 'x', id: 'y.x')
=> "1"

The problem I think, is that we're trying to add singleton methods to an arbitrary Ruby object here:

https://github.com/infochimps-labs/vayacondios/blob/leslie/lib/vayacondios/client/http_client.rb#L270

but some objects, apparently immutable objects, do not allow their singleton metaclasses to be modified:

>> x = 'hi'; def x.foo() end
=> nil
>> x = {}; def x.foo() end
=> nil
>> x = :sym; def x.foo() end
TypeError: can't define singleton method "foo" for Symbol
        from (irb):16
        from /Users/joshbronson/.rbenv/versions/1.9.3-p125/bin/irb:12:in `<main>'
>> x = 1; def x.foo() end
TypeError: can't define singleton method "foo" for Fixnum
        from (irb):17
        from /Users/joshbronson/.rbenv/versions/1.9.3-p125/bin/irb:12:in `<main>'

We need a different strategy for combining the http response with the parsed object. (There should probably be a container that has both.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant