Module: ContentfulLite::Validations::Entry

Extended by:
ActiveSupport::Concern
Included in:
Entry
Defined in:
lib/contentful_lite/validations/entry.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.validates_included_asset(*attr_names, **options) ⇒ Object

Adds a validation on one or more fields to ensure it’s a reference field and the values are assets

Parameters:

  • attr_names (Array<string>)

    the fields to validate

  • options (Hash)

    the options Hash

Options Hash (**options):

  • :type (Array<Class>)

    the asset content types that will be allowed

  • :allow_blank (Boolean)

    if true it allows the field to be empty

  • :array (Boolean)

    if true, the field must be an array of references. If not, it must be a single reference.



47
48
49
50
51
# File 'lib/contentful_lite/validations/entry.rb', line 47

class_methods do
  def validates_included_asset(*attr_names)
    validates_with IncludedAssetValidator, _merge_attributes(attr_names)
  end
end

.validates_included_entry(*attr_names, **options) ⇒ Object

Adds a validation on one or more fields to ensure it’s a reference field and the values are entries with one of the specified types

Parameters:

  • attr_names (Array<string>)

    the fields to validate

  • options (Hash)

    the options Hash

Options Hash (**options):

  • :allowed_models (Array<Class>)

    the contentful content types that will be allowed

  • :allow_blank (Boolean)

    if true it allows the field to be empty

  • :array (Boolean)

    if true, the field must be an array of references. If not, it must be a single reference.



32
33
34
35
36
# File 'lib/contentful_lite/validations/entry.rb', line 32

class_methods do
  def validates_included_entry(*attr_names)
    validates_with IncludedEntryValidator, _merge_attributes(attr_names)
  end
end

Instance Method Details

#errors_for_all_localesHash

Gets the error messages for all the locales at once

Returns:

  • (Hash)

    a hash with locale as keys and errors as values



63
64
65
# File 'lib/contentful_lite/validations/entry.rb', line 63

def errors_for_all_locales
  @errors
end

#valid_for_all_locales?boolean

Validates all locales

Returns:

  • (boolean)

    is entry valid across al locales?



55
56
57
58
59
# File 'lib/contentful_lite/validations/entry.rb', line 55

def valid_for_all_locales?
  locales.map do |locale|
    valid?(locale: locale)
  end.all?
end