Class: DataMapper::Matchers::ValidateFormatOf
Instance Method Summary
collapse
#description, #initialize, set_default_msg_reg, set_validation_subject, #with_message
Instance Method Details
#failure_message ⇒ Object
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
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_message ⇒ Object
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
|