Module: DatabaseValidations::Storage
- Defined in:
- lib/database_validations/lib/storage.rb
Class Method Summary collapse
Class Method Details
.prepare(model) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/database_validations/lib/storage.rb', line 5 def prepare(model) model.class_attribute :_db_validators, instance_writer: false model._db_validators = {} model.validators.each do |validator| case validator when DbUniquenessValidator then process(validator, UniquenessKeyExtractor, model) when DbPresenceValidator then process(validator, PresenceKeyExtractor, model) else next end end end |
.prepared?(model) ⇒ Boolean
24 25 26 |
# File 'lib/database_validations/lib/storage.rb', line 24 def prepared?(model) model.respond_to?(:_db_validators) end |
.process(validator, extractor, model) ⇒ Object
18 19 20 21 22 |
# File 'lib/database_validations/lib/storage.rb', line 18 def process(validator, extractor, model) extractor.attribute_by_key(validator).each do |key, attribute| model._db_validators[key] = AttributeValidator.new(attribute, validator) end end |