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

Contentful::Array doesn't marshal/unmarshal properly #132

Closed
plexus opened this issue Apr 11, 2017 · 3 comments · Fixed by #135
Closed

Contentful::Array doesn't marshal/unmarshal properly #132

plexus opened this issue Apr 11, 2017 · 3 comments · Fixed by #135
Assignees
Labels

Comments

@plexus
Copy link

plexus commented Apr 11, 2017

Contentful::Array inherits from Contentful::BaseResource, which implements custom marshal/unmarshal hooks.

Array uses several instance variables not present in its superclass, so after unmarshalling you end up with a broken instance.

I'm working around it now with this monkey patch, but would be great if this could be addressed.

Thanks!

module Contentful
  class Array
    def marshal_dump
      [raw, @endpoint]
    end

    def marshal_load(input)
      super(input[0])
      @endpoint = input[1]
      @total = item.fetch('total', nil)
      @limit = item.fetch('limit', nil)
      @skip = item.fetch('skip', nil)
      @items = item.fetch('items', [])
    end
  end
end
@dlitvakb
Copy link
Contributor

Hey @plexus,

Thanks for noticing this, I'll be taking care of it within the next 2 weeks.

Cheers

@dlitvakb dlitvakb added the bug label Apr 24, 2017
@dlitvakb dlitvakb self-assigned this Apr 24, 2017
@plexus
Copy link
Author

plexus commented Apr 24, 2017

Great, thanks a lot! Just FYI in the end we went with this patch, it plays better with the changes to marshaling in the latest version of contentful.rb

class Contentful::Array
  def marshal_dump
    super.merge(endpoint: @endpoint)
  end

  def marshal_load(raw_object)
    super
    @endpoint = raw_object[:endpoint]
    @total = @raw.fetch("total", nil)
    @limit = @raw.fetch("limit", nil)
    @skip = @raw.fetch("skip", nil)
    @items = @raw.fetch("items", [])
  end
end

@dlitvakb
Copy link
Contributor

Hey @plexus,

The fix came way earlier :) Just looking for a reviewer from my team to merge, thank you very much for the help.

Cheers

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

Successfully merging a pull request may close this issue.

2 participants