Sha256: c2406188291f2ea77f200ee802ec7d2d5ff65279efc6fe2a790b8f455d8f8516

Contents?: true

Size: 1.08 KB

Versions: 2

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

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

2 entries across 2 versions & 1 rubygems

Version Path
contentful-management-3.10.0 lib/contentful/management/resource/refresher.rb
contentful-management-3.9.0 lib/contentful/management/resource/refresher.rb