Class: DataMapper::Matchers::ValidateFormatOf

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

Instance Method Summary collapse

Methods inherited from ValidationMatcher

#description, #initialize, set_default_msg_reg, set_validation_subject, #with_message

Constructor Details

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

Instance Method Details

#failure_messageObject


27
28
29
30
31
# File 'lib/dm/matchers/validate_format_of.rb', line 27

def failure_message
  msg = "expected to validate #{@validation_subject} of #{@property} with #{@format.inspect}"
  msg = %Q'#{msg} and message "#{@msg}"' if @msg
  msg
end

#matches?(model) ⇒ Boolean

Returns:

  • (Boolean)

15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dm/matchers/validate_format_of.rb', line 15

def matches?(model)
  model_class = model.is_a?(Class) ? model : model.class
  validators = model_class.validators.contexts[:default]
  format_of = validators.find do |validator|
    validator.is_a? DataMapper::Validations::FormatValidator and validator.field_name == @property
  end
  return false unless format_of
  return false unless format_of.options[:with] == @format
  return false if     @msg and @msg != format_of.options[:message]
  true
end

#negative_failure_messageObject


33
34
35
36
37
# File 'lib/dm/matchers/validate_format_of.rb', line 33

def negative_failure_message
  msg = "expected to not validate #{@validation_subject} of #{@property} with #{@format.inspect}"
  msg = %Q'#{msg} and message "#{@msg}"' if @msg
  msg
end

#with(format) ⇒ Object


10
11
12
13
# File 'lib/dm/matchers/validate_format_of.rb', line 10

def with(format)
  @format = format
  self
end