Small refactoring in NumericTypeMatcher
This commit is contained in:
parent
8bc8083d77
commit
fc010175c7
|
@ -11,6 +11,7 @@ module Shoulda
|
|||
:_after_setting_value,
|
||||
:attribute_to_set,
|
||||
:description,
|
||||
:expects_strict?,
|
||||
:model,
|
||||
:last_value_set,
|
||||
:simple_description,
|
||||
|
|
|
@ -8,44 +8,21 @@ module Shoulda
|
|||
class NumericTypeMatcher
|
||||
extend Forwardable
|
||||
|
||||
def_delegators :disallow_value_matcher, :matches?, :failure_message,
|
||||
:failure_message_when_negated
|
||||
def_delegators(
|
||||
:disallow_value_matcher,
|
||||
:expects_custom_validation_message?,
|
||||
:expects_strict?,
|
||||
:failure_message,
|
||||
:failure_message_when_negated,
|
||||
:matches?,
|
||||
:on,
|
||||
:strict,
|
||||
:with_message,
|
||||
)
|
||||
|
||||
def initialize(numeric_type_matcher, attribute, options = {})
|
||||
def initialize(numeric_type_matcher, attribute)
|
||||
@numeric_type_matcher = numeric_type_matcher
|
||||
@attribute = attribute
|
||||
@options = options
|
||||
@message = nil
|
||||
@context = nil
|
||||
@expects_strict = false
|
||||
@expects_custom_validation_message = false
|
||||
end
|
||||
|
||||
def with_message(message)
|
||||
if message
|
||||
@expects_custom_validation_message = true
|
||||
@message = message
|
||||
end
|
||||
|
||||
self
|
||||
end
|
||||
|
||||
def expects_custom_validation_message?
|
||||
@expects_custom_validation_message
|
||||
end
|
||||
|
||||
def strict
|
||||
@expects_strict = true
|
||||
self
|
||||
end
|
||||
|
||||
def expects_strict?
|
||||
@expects_strict
|
||||
end
|
||||
|
||||
def on(context)
|
||||
@context = context
|
||||
self
|
||||
end
|
||||
|
||||
def allowed_type_name
|
||||
|
@ -79,18 +56,6 @@ module Shoulda
|
|||
DisallowValueMatcher.new(disallowed_value).tap do |matcher|
|
||||
matcher.for(attribute)
|
||||
wrap_disallow_value_matcher(matcher)
|
||||
|
||||
if @message
|
||||
matcher.with_message(@message)
|
||||
end
|
||||
|
||||
if expects_strict?
|
||||
matcher.strict
|
||||
end
|
||||
|
||||
if @context
|
||||
matcher.on(@context)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue