Class: Contentful::Validations::PresenceValidation
- Inherits:
-
Object
- Object
- Contentful::Validations::PresenceValidation
- Defined in:
- lib/contentful_model/validations/validates_presence_of.rb
Overview
Actual validation
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Instance Method Summary collapse
-
#initialize(fields) ⇒ PresenceValidation
constructor
A new instance of PresenceValidation.
- #validate(entry) ⇒ Object
Constructor Details
#initialize(fields) ⇒ PresenceValidation
Returns a new instance of PresenceValidation.
22 23 24 |
# File 'lib/contentful_model/validations/validates_presence_of.rb', line 22 def initialize(fields) @fields = fields end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
20 21 22 |
# File 'lib/contentful_model/validations/validates_presence_of.rb', line 20 def fields @fields end |
Instance Method Details
#validate(entry) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/contentful_model/validations/validates_presence_of.rb', line 26 def validate(entry) errors = [] fields.each do |field| errors << "#{field} is required" unless entry.respond_to?(field) && entry.public_send(field).present? end errors end |