Class: DataMapper::Matchers::ValidatePresenceOf

Inherits:
ValidationMatcher show all
Defined in:
lib/dm/matchers/validate_presence_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_presence_of.rb', line 10

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

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