class Shoulda::Matchers::ActiveModel::ValidateExclusionOfMatcher
@private
Public Class Methods
new(attribute)
click to toggle source
Calls superclass method
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 123 def initialize(attribute) super(attribute) @expected_message = :exclusion @array = nil @range = nil end
Public Instance Methods
in_array(array)
click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 130 def in_array(array) @array = array self end
in_range(range)
click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 135 def in_range(range) @range = range @minimum = range.first @maximum = range.max self end
matches?(subject)
click to toggle source
Calls superclass method
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 159 def matches?(subject) super(subject) if @range allows_lower_value && disallows_minimum_value && allows_higher_value && disallows_maximum_value elsif @array disallows_all_values_in_array? end end
simple_description()
click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 142 def simple_description if @range "validate that :#{@attribute} lies outside the range " + Shoulda::Matchers::Util.inspect_range(@range) else description = "validate that :#{@attribute}" if @array.many? description << " is neither #{inspected_array}" else description << " is not #{inspected_array}" end description end end
Private Instance Methods
allows_higher_value()
click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 184 def allows_higher_value allows_value_of(@maximum + 1, @expected_message) end
allows_lower_value()
click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 180 def allows_lower_value @minimum == 0 || allows_value_of(@minimum - 1, @expected_message) end
disallows_all_values_in_array?()
click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 174 def disallows_all_values_in_array? @array.all? do |value| disallows_value_of(value, @expected_message) end end
disallows_maximum_value()
click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 192 def disallows_maximum_value disallows_value_of(@maximum, @expected_message) end
disallows_minimum_value()
click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 188 def disallows_minimum_value disallows_value_of(@minimum, @expected_message) end
inspect_message()
click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 196 def inspect_message if @range @range.inspect else @array.inspect end end
inspected_array()
click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 204 def inspected_array Shoulda::Matchers::Util.inspect_values(@array).to_sentence( two_words_connector: " nor ", last_word_connector: ", nor " ) end