class Shoulda::Matchers::ActiveModel::ValidateFormatOfMatcher
:nodoc:
def allow_blank(allow_blank = true)
def allow_blank(allow_blank = true) @options[:allow_blank] = allow_blank self end
def allow_nil(allow_nil = true)
def allow_nil(allow_nil = true) @options[:allow_nil] = allow_nil self end
def allows_blank_value?
def allows_blank_value? if @options.key?(:allow_blank) @options[:allow_blank] == allows_value_of('') else true end end
def allows_nil_value?
def allows_nil_value? if @options.key?(:allow_nil) @options[:allow_nil] == allows_value_of(nil) else true end end
def description
def description "have a valid format for #{@attribute}" end
def initialize(attribute)
def initialize(attribute) ActiveSupport::Deprecation.warn 'The validate_format_of matcher is deprecated and will be removed in 2.0' super @options = {} end
def matches?(subject)
def matches?(subject) super(subject) @expected_message ||= :invalid if @value_to_fail disallows_value_of(@value_to_fail, @expected_message) && allows_blank_value? && allows_nil_value? else allows_value_of(@value_to_pass, @expected_message) && allows_blank_value? && allows_nil_value? end end
def not_with(value)
def not_with(value) if @value_to_pass raise 'You may not call both with and not_with' else @value_to_fail = value self end end
def with(value)
def with(value) if @value_to_fail raise 'You may not call both with and not_with' else @value_to_pass = value self end end
def with_message(message)
def with_message(message) if message @expected_message = message end self end