Class: ContentfulLite::Validations::IncludedEntryValidator Private
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ContentfulLite::Validations::IncludedEntryValidator
- Includes:
- IncludedChildValidator
- Defined in:
- lib/contentful_lite/validations/included_entry_validator.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary
Constants included from IncludedChildValidator
ContentfulLite::Validations::IncludedChildValidator::BASE_OPTIONS
Instance Method Summary collapse
- #invalid_model?(value) ⇒ Boolean private
- #validate_child(record, attr_name, value, idx = nil) ⇒ Object private
Methods included from IncludedChildValidator
Instance Method Details
#invalid_model?(value) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
17 18 19 20 21 |
# File 'lib/contentful_lite/validations/included_entry_validator.rb', line 17 def invalid_model?(value) return false unless [:allowed_models] [:allowed_models]&.none?{ |type| value.is_a?(type) } end |
#validate_child(record, attr_name, value, idx = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
8 9 10 11 12 13 14 15 |
# File 'lib/contentful_lite/validations/included_entry_validator.rb', line 8 def validate_child(record, attr_name, value, idx = nil) unless value.is_a?(ContentfulLite::Entry) record_error(record, attr_name, "value#{idx} is not a published entry") return end record_error(record, attr_name, "value has invalid child entry #{value.id}") unless value.valid?(locale: record.locale) record_error(record, attr_name, "value#{idx} has an invalid entry model. Expecting #{[:allowed_models]}") if invalid_model?(value) end |