Sha256: 89e7939ce9f365e61b7b885aacedca24f3124842d1e43dfda9ab6ad01a5bc612

Contents?: true

Size: 1.35 KB

Versions: 12

Compression:

Stored size: 1.35 KB

Contents

module Contentful
  module Management
    module Resource
      # Adds the feature to have system properties to a Resource.
      module SystemProperties
        SYS_COERCIONS = {
          type: :string,
          id: :string,
          space: nil,
          contentType: nil,
          linkType: :string,
          revision: :integer,
          createdAt: :date,
          updatedAt: :date,
          locale: :string
        }
        attr_reader :sys

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

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

        module ClassMethods
          def sys_coercions
            SYS_COERCIONS
          end
        end

        def self.included(base)
          base.extend(ClassMethods)

          base.sys_coercions.keys.each { |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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
contentful-management-0.8.0 lib/contentful/management/resource/system_properties.rb
contentful-management-0.7.3 lib/contentful/management/resource/system_properties.rb
contentful-management-0.7.2 lib/contentful/management/resource/system_properties.rb
contentful-management-0.7.1 lib/contentful/management/resource/system_properties.rb
contentful-management-0.7.0 lib/contentful/management/resource/system_properties.rb
contentful-management-0.6.1 lib/contentful/management/resource/system_properties.rb
contentful-management-0.6.0 lib/contentful/management/resource/system_properties.rb
contentful-management-0.5.0 lib/contentful/management/resource/system_properties.rb
contentful-management-0.4.1 lib/contentful/management/resource/system_properties.rb
contentful-management-0.4.0 lib/contentful/management/resource/system_properties.rb
contentful-management-0.3.1 lib/contentful/management/resource/system_properties.rb
contentful-management-0.3.0 lib/contentful/management/resource/system_properties.rb