Sha256: 6e6922f1ee10261feaabf785c075c55152ce742042970b79ad87e69089a25bb4

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

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
          resource = refresh_find
          refresh_data(resource) if resource.is_a? self.class
        end

        # @private
        def refresh_find
          return self.class.find(client, space.id, environment_id, id) if environment_id
          self.class.find(client, space.id, id)
        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)
            @_metadata = resource.instance_variable_get(:@_metadata)
            self
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
contentful-management-3.8.0 lib/contentful/management/resource/refresher.rb
contentful-management-3.7.0 lib/contentful/management/resource/refresher.rb
contentful-management-3.6.0 lib/contentful/management/resource/refresher.rb
contentful-management-3.5.0 lib/contentful/management/resource/refresher.rb
contentful-management-3.4.0 lib/contentful/management/resource/refresher.rb