Class: Dis::Validations::DataPresence
- Inherits:
-
ActiveModel::Validator
- Object
- ActiveModel::Validator
- Dis::Validations::DataPresence
- Defined in:
- lib/dis/validations/data_presence.rb
Overview
Dis Data Presence Validation
Validates that data has been assigned to a Model record. Empty strings are treated as missing data.
Class Method Summary collapse
Instance Method Summary collapse
-
#validate(record) ⇒ void
Validates that a record has data, either freshly assigned or persisted in the storage.
Class Method Details
.empty_hash ⇒ Object
25 26 27 |
# File 'lib/dis/validations/data_presence.rb', line 25 def empty_hash @empty_hash ||= Dis::Storage.file_digest("") end |
Instance Method Details
#validate(record) ⇒ void
This method returns an undefined value.
Validates that a record has data, either freshly assigned or persisted in the storage. Adds a :blank error on :data if not.
18 19 20 21 22 |
# File 'lib/dis/validations/data_presence.rb', line 18 def validate(record) return if record.data? && record.content_hash != self.class.empty_hash record.errors.add(:data, :blank) end |