Class: Shoulda::Matchers::ActiveModel::NumericalityMatchers::RangeMatcher
- Inherits:
-
ValidationMatcher
- Object
- ValidationMatcher
- Shoulda::Matchers::ActiveModel::NumericalityMatchers::RangeMatcher
- Defined in:
- lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb
Constant Summary collapse
- OPERATORS =
[:>=, :<=].freeze
Instance Attribute Summary
Attributes included from Qualifiers::IgnoringInterferenceByWriter
#ignore_interference_by_writer
Instance Method Summary collapse
-
#initialize(numericality_matcher, attribute, range) ⇒ RangeMatcher
constructor
A new instance of RangeMatcher.
- #matches?(subject) ⇒ Boolean
- #range_description ⇒ Object
- #simple_description ⇒ Object
- #submatchers ⇒ Object
Methods inherited from ValidationMatcher
#allow_blank, #description, #does_not_match?, #expects_custom_validation_message?, #expects_strict?, #failure_message, #failure_message_when_negated, #on, #strict, #with_message
Methods included from Qualifiers::IgnoringInterferenceByWriter
#ignoring_interference_by_writer
Constructor Details
#initialize(numericality_matcher, attribute, range) ⇒ RangeMatcher
Returns a new instance of RangeMatcher.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb', line 13 def initialize(numericality_matcher, attribute, range) super(attribute) unless numericality_matcher.respond_to? :diff_to_compare raise ArgumentError, 'numericality_matcher is invalid' end @numericality_matcher = numericality_matcher @range = range @attribute = attribute end |
Instance Method Details
#matches?(subject) ⇒ Boolean
24 25 26 27 |
# File 'lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb', line 24 def matches?(subject) @subject = subject submatchers.matches?(subject) end |
#range_description ⇒ Object
41 42 43 |
# File 'lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb', line 41 def range_description "from #{Shoulda::Matchers::Util.inspect_range(@range)}" end |
#simple_description ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb', line 29 def simple_description description = '' if expects_strict? description << ' strictly' end description + "disallow :#{attribute} from being a number that is not " + range_description end |
#submatchers ⇒ Object
45 46 47 |
# File 'lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb', line 45 def submatchers @_submatchers ||= NumericalityMatchers::Submatchers.new(build_submatchers) end |