Sha256: 34a6bbbde467fcce8e68354b0c292a120fd70f530ffadfc88bd005f74ce33ea0

Contents?: true

Size: 917 Bytes

Versions: 1

Compression:

Stored size: 917 Bytes

Contents

# -*- encoding: utf-8 -*-
module Contentful
  module Management
    module Resource
      # Adds the feature to have properties and system data reload for Resource.
      module Refresher
        # Reload an object
        # Updates the current version of the object to the version on the system
        def reload
          resource = self.is_a?(Space) ? self.class.find(id) : self.class.find(space.id, id)
          refresh_data(resource) if resource.is_a? self.class
        end

        def refresh_data(resource)
          if resource.is_a? Error
            resource
          else
            @properties = resource.instance_variable_get(:@properties)
            @fields = resource.instance_variable_get(:@fields) if self.is_a?(Contentful::Management::Entry)
            @sys = resource.instance_variable_get(:@sys).merge(locale: locale)
            self
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
contentful-management-0.1.0 lib/contentful/management/resource/refresher.rb