Class: DataMapper::Matchers::ValidateUniquenessOf

Inherits:
ValidationMatcher show all
Defined in:
lib/dm/matchers/validate_uniqueness_of.rb

Instance Method Summary collapse

Methods inherited from ValidationMatcher

#description, #failure_message, #initialize, #negative_failure_message, set_default_msg_reg, set_validation_subject, #with_message

Constructor Details

This class inherits a constructor from DataMapper::Matchers::ValidationMatcher

Instance Method Details

#matches?(model) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dm/matchers/validate_uniqueness_of.rb', line 10

def matches?(model)
  model_class = model.is_a?(Class) ? model : model.class

  validators = model_class.validators.contexts[:default]
  uniqueness_of = validators.find do |validator|
    validator.is_a? DataMapper::Validations::UniquenessValidator and validator.field_name == @property
  end
  return false unless uniqueness_of
  return false if @msg and @msg != uniqueness_of.options[:message]
  true
end