Sha256: 88a2c85199cb2c75b50b77f4b76a30fdf05beba308e5fa0b51ea60112ec5dc20

Contents?: true

Size: 1.28 KB

Versions: 14

Compression:

Stored size: 1.28 KB

Contents

require_relative 'resource'

module Contentful
  module Management
    # A ContentType's validations schema
    class Validation
      # Properties not specific to a field type validation
      NON_TYPE_PROPERTIES = %i[validations message].freeze

      include Contentful::Management::Resource

      property :in, :array
      property :size, :hash
      property :range, :hash
      property :regexp, :hash
      property :unique, :boolean
      property :present, :boolean
      property :linkField, :boolean
      property :assetFileSize, :hash
      property :linkContentType, :array
      property :linkMimetypeGroup, :string
      property :assetImageDimensions, :hash
      property :enabledNodeTypes, :array
      property :enabledMarks, :array
      property :nodes, :hash
      property :message, :string

      # @private
      def properties_to_hash
        properties.each_with_object({}) do |(key, value), results|
          results[key] = value if Field.value_exists?(value)
        end
      end

      # Returns type of validation
      # @return [Symbol]
      def type
        properties.keys.reject { |key| NON_TYPE_PROPERTIES.include?(key) }.each do |type|
          value = send(Support.snakify(type))
          return type if !value.nil? && value
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
contentful-management-3.8.0 lib/contentful/management/validation.rb
contentful-management-3.7.0 lib/contentful/management/validation.rb
contentful-management-3.6.0 lib/contentful/management/validation.rb
contentful-management-3.5.0 lib/contentful/management/validation.rb
contentful-management-3.4.0 lib/contentful/management/validation.rb
contentful-management-3.3.0 lib/contentful/management/validation.rb
contentful-management-3.2.0 lib/contentful/management/validation.rb
contentful-management-3.1.0 lib/contentful/management/validation.rb
contentful-management-3.0.0 lib/contentful/management/validation.rb
contentful-management-2.13.1 lib/contentful/management/validation.rb
contentful-management-2.13.0 lib/contentful/management/validation.rb
contentful-management-2.12.1 lib/contentful/management/validation.rb
contentful-management-2.12.0 lib/contentful/management/validation.rb
contentful-management-2.11.0 lib/contentful/management/validation.rb