Class: Dis::Validations::DataPresence

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/dis/validations/data_presence.rb

Overview

Dis Data Presence Validation

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.empty_hashObject



17
18
19
# File 'lib/dis/validations/data_presence.rb', line 17

def empty_hash
  @empty_hash ||= Dis::Storage.file_digest("")
end

Instance Method Details

#validate(record) ⇒ Object

Validates that a record has data, either freshly assigned or persisted in the storage. Adds a ‘:blank` error on `:data`if not.



10
11
12
13
14
# File 'lib/dis/validations/data_presence.rb', line 10

def validate(record)
  return if record.data? && record.content_hash != self.class.empty_hash

  record.errors.add(:data, :blank)
end