Sha256: 9b5fb9c76f5a0a2425db7dfd6a756f32ebe89423aceca884dc9e668ab61d2042

Contents?: true

Size: 918 Bytes

Versions: 1

Compression:

Stored size: 918 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.0.3 lib/contentful/management/resource/refresher.rb