Sha256: d726c14c3f3d2162ad348182e5e09039c0bc308e0644b744268505a58cebac89

Contents?: true

Size: 915 Bytes

Versions: 2

Compression:

Stored size: 915 Bytes

Contents

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
          self_class = self.class
          resource = self.is_a?(Space) ? self_class.find(client, id) : self_class.find(client, space.id, id)
          refresh_data(resource) if resource.is_a? self_class
        end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
contentful-management-1.0.1 lib/contentful/management/resource/refresher.rb
contentful-management-1.0.0 lib/contentful/management/resource/refresher.rb