Sha256: 589a0c3e92fb447257b38a504279a25c8d57f5cbc66cdaacbb5835192077cace

Contents?: true

Size: 889 Bytes

Versions: 3

Compression:

Stored size: 889 Bytes

Contents

require_relative 'resource'

module Contentful
  module Management
    # A ContentType's validations schema
    class Validation
      include Contentful::Management::Resource

      property :in, :array
      property :size, :hash
      property :present, :boolean
      property :regexp, :hash
      property :linkContentType, :array
      property :range, :hash
      property :linkMimetypeGroup, :string
      property :linkField, :boolean

      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
      def type
        properties.keys.reject { |key| key == :validations }.each do |type|
          value = self.send(Support.snakify(type))
          return type if !value.nil? && value
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
contentful-management-0.8.0 lib/contentful/management/validation.rb
contentful-management-0.7.3 lib/contentful/management/validation.rb
contentful-management-0.7.2 lib/contentful/management/validation.rb