Sha256: 94764739588fec56b6abb6e902601a2e1da6b19d9a7aae736262eee2686ddda6

Contents?: true

Size: 1.56 KB

Versions: 21

Compression:

Stored size: 1.56 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,
          publishedAt: :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

21 entries across 21 versions & 1 rubygems

Version Path
contentful-management-3.8.0 lib/contentful/management/resource/system_properties.rb
contentful-management-3.7.0 lib/contentful/management/resource/system_properties.rb
contentful-management-3.6.0 lib/contentful/management/resource/system_properties.rb
contentful-management-3.5.0 lib/contentful/management/resource/system_properties.rb
contentful-management-3.4.0 lib/contentful/management/resource/system_properties.rb
contentful-management-3.3.0 lib/contentful/management/resource/system_properties.rb
contentful-management-3.2.0 lib/contentful/management/resource/system_properties.rb
contentful-management-3.1.0 lib/contentful/management/resource/system_properties.rb
contentful-management-3.0.0 lib/contentful/management/resource/system_properties.rb
contentful-management-2.13.1 lib/contentful/management/resource/system_properties.rb
contentful-management-2.13.0 lib/contentful/management/resource/system_properties.rb
contentful-management-2.12.1 lib/contentful/management/resource/system_properties.rb
contentful-management-2.12.0 lib/contentful/management/resource/system_properties.rb
contentful-management-2.11.0 lib/contentful/management/resource/system_properties.rb
contentful-management-2.10.0 lib/contentful/management/resource/system_properties.rb
contentful-management-2.9.1 lib/contentful/management/resource/system_properties.rb
contentful-management-2.9.0 lib/contentful/management/resource/system_properties.rb
contentful-management-2.8.2 lib/contentful/management/resource/system_properties.rb
contentful-management-2.8.1 lib/contentful/management/resource/system_properties.rb
contentful-management-2.8.0 lib/contentful/management/resource/system_properties.rb