Sha256: 093353af6718c09566ef51065725fe26b99a3227278fc290920fcba9f2b26358

Contents?: true

Size: 1.53 KB

Versions: 18

Compression:

Stored size: 1.53 KB

Contents

module Contentful
  module Management
    module Resource
      # Adds the feature to have system properties to a Resource.
      module SystemProperties
        # @private
        # Coercions for System Properties to native types
        SYS_COERCIONS = {
          type: :string,
          id: :string,
          space: nil,
          contentType: nil,
          linkType: :string,
          revision: :integer,
          createdAt: :date,
          updatedAt: :date,
          locale: :string
        }.freeze

        attr_reader :sys

        # @private
        def initialize(object = { 'sys' => nil }, *)
          super
          object ||= { 'sys' => nil }
          @sys = extract_from_object object['sys'], :sys
        end

        # @private
        def inspect(info = nil)
          if sys.empty?
            super(info)
          else
            super("#{info} @sys=#{sys.inspect}")
          end
        end

        # @private
        module ClassMethods
          # @private
          def sys_coercions
            SYS_COERCIONS
          end
        end

        # @private
        def self.included(base)
          base.extend(ClassMethods)

          base.sys_coercions.keys.each do |name|
            accessor_name = Contentful::Management::Support.snakify(name)
            base.send :define_method, accessor_name do
              sys[name.to_sym]
            end
            base.send :define_method, "#{accessor_name}=" do |value|
              sys[name.to_sym] = value
            end
          end
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
contentful-management-2.6.0 lib/contentful/management/resource/system_properties.rb
contentful-management-2.5.0 lib/contentful/management/resource/system_properties.rb
contentful-management-2.4.0 lib/contentful/management/resource/system_properties.rb
contentful-management-2.3.0 lib/contentful/management/resource/system_properties.rb
contentful-management-2.2.2 lib/contentful/management/resource/system_properties.rb
contentful-management-2.2.1 lib/contentful/management/resource/system_properties.rb
contentful-management-2.2.0 lib/contentful/management/resource/system_properties.rb
contentful-management-2.1.1 lib/contentful/management/resource/system_properties.rb
contentful-management-2.1.0 lib/contentful/management/resource/system_properties.rb
contentful-management-2.0.2 lib/contentful/management/resource/system_properties.rb
contentful-management-2.0.1 lib/contentful/management/resource/system_properties.rb
contentful-management-2.0.0 lib/contentful/management/resource/system_properties.rb
contentful-management-1.10.1 lib/contentful/management/resource/system_properties.rb
contentful-management-1.10.0 lib/contentful/management/resource/system_properties.rb
contentful-management-1.9.0 lib/contentful/management/resource/system_properties.rb
contentful-management-1.8.1 lib/contentful/management/resource/system_properties.rb
contentful-management-1.8.0 lib/contentful/management/resource/system_properties.rb
contentful-management-1.7.0 lib/contentful/management/resource/system_properties.rb