Class: ROM::Model::Validator::UniquenessValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ROM::Model::Validator::UniquenessValidator
- Defined in:
- lib/rom/rails/model/validator/uniqueness_validator.rb
Overview
Uniqueness validation
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
private
Relation validator class.
-
#message ⇒ String, Symbol
readonly
private
error message.
Instance Method Summary collapse
-
#initialize(options) ⇒ UniquenessValidator
constructor
private
A new instance of UniquenessValidator.
-
#validate_each(validator, name, value) ⇒ Object
private
Hook called by ActiveModel internally.
Constructor Details
#initialize(options) ⇒ UniquenessValidator
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.
Returns a new instance of UniquenessValidator.
23 24 25 26 27 |
# File 'lib/rom/rails/model/validator/uniqueness_validator.rb', line 23 def initialize() super @klass = .fetch(:class) @message = .fetch(:message) { :taken } end |
Instance Attribute Details
#klass ⇒ Object (readonly)
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.
Relation validator class
13 14 15 |
# File 'lib/rom/rails/model/validator/uniqueness_validator.rb', line 13 def klass @klass end |
#message ⇒ String, Symbol (readonly)
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.
error message
20 21 22 |
# File 'lib/rom/rails/model/validator/uniqueness_validator.rb', line 20 def @message end |
Instance Method Details
#validate_each(validator, name, value) ⇒ 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.
Hook called by ActiveModel internally
32 33 34 |
# File 'lib/rom/rails/model/validator/uniqueness_validator.rb', line 32 def validate_each(validator, name, value) validator.errors.add(name, ) unless unique?(name, value) end |