class Shoulda::Matchers::ActiveModel::NumericalityMatchers::RangeMatcher
@private
Constants
- OPERATORS
Public Class Methods
new(numericality_matcher, attribute, range)
click to toggle source
Calls superclass method
# 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
Public Instance Methods
matches?(subject)
click to toggle source
# File lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb, line 24 def matches?(subject) @subject = subject submatchers.matches?(subject) end
range_description()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb, line 45 def submatchers @_submatchers ||= NumericalityMatchers::Submatchers.new(build_submatchers) end
Private Instance Methods
build_comparison_submatcher(value, operator)
click to toggle source
# File lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb, line 61 def build_comparison_submatcher(value, operator) ComparisonMatcher.new(@numericality_matcher, value, operator). for(@attribute). with_message(@message). on(@context) end
build_submatchers()
click to toggle source
# File lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb, line 51 def build_submatchers submatcher_combos.map do |value, operator| build_comparison_submatcher(value, operator) end end
submatcher_combos()
click to toggle source
# File lib/shoulda/matchers/active_model/numericality_matchers/range_matcher.rb, line 57 def submatcher_combos @range.minmax.zip(OPERATORS) end