Skip to content

Failing to restore resource.rels[:x].get after marshal_load #53

@dazza-codes

Description

@dazza-codes

Finding it difficult to restore functionality after serializing/deserialzing a Sawyer::Resource.

For example, starting with the github Octokit gem

repo = Octokit.repo('kubernetes/kubernetes');
repo.class #=> Sawyer::Resource

users = repo.rels[:contributors].get.data;
users.class #=> Array

dumped = Marshal.dump( repo.marshal_dump );
dumped.class #=> String

agent = Sawyer::Agent.new('https://api.github.com/', links_parser: Sawyer::LinkParsers::Simple.new)
resource = Sawyer::Resource.new(agent)
resource.marshal_load(Marshal.restore(dumped))
resource.class #=> Sawyer::Resource
resource.rels.class #=> Sawyer::Relation::Map
resource.rels[:contributors]
#=> #<Sawyer::Relation: contributors: get #<Addressable::Template:0x000055be59bf7030>>

resource.rels[:contributors].get
NoMethodError: undefined method `get' for nil:NilClass
Did you mean?  gets
               gem
from {HOME}/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/sawyer-0.8.1/lib/sawyer/agent.rb:94:in `call'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions