class Shoulda::Matchers::ActiveModel::ValidateExclusionOfMatcher
@private
Public Class Methods
Source
# 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
Calls superclass method
Public Instance Methods
Source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 173 def does_not_match?(subject) super(subject) if @range disallows_lower_value || allows_minimum_value || allows_maximum_value || disallows_higher_value elsif @array allows_any_values_in_array? end end
Calls superclass method
Source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 130 def in_array(array) @array = array self end
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
Source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 160 def matches?(subject) super(subject) if @range allows_lower_value && disallows_minimum_value && disallows_maximum_value && allows_higher_value elsif @array disallows_all_values_in_array? end end
Calls superclass method
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}" description << if @array.many? " is neither #{inspected_array}" else " is not #{inspected_array}" end description end end
Private Instance Methods
Source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 188 def allows_any_values_in_array? @array.any? do |value| allows_value_of(value, @expected_message) end end
Source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 224 def allows_higher_value allows_value_of(@maximum + 1, @expected_message) end
Source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 200 def allows_lower_value @minimum == 0 || allows_value_of(@minimum - 1, @expected_message) end
Source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 216 def allows_maximum_value allows_value_of(@maximum, @expected_message) end
Source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 208 def allows_minimum_value allows_value_of(@minimum, @expected_message) end
Source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 194 def disallows_all_values_in_array? @array.all? do |value| disallows_value_of(value, @expected_message) end end
Source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 228 def disallows_higher_value disallows_value_of(@maximum + 1, @expected_message) end
Source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 204 def disallows_lower_value @minimum != 0 && disallows_value_of(@minimum - 1, @expected_message) end
Source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 220 def disallows_maximum_value disallows_value_of(@maximum, @expected_message) end
Source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 212 def disallows_minimum_value disallows_value_of(@minimum, @expected_message) end
Source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 232 def inspect_message if @range @range.inspect else @array.inspect end end
Source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 240 def inspected_array Shoulda::Matchers::Util.inspect_values(@array).to_sentence( two_words_connector: ' nor ', last_word_connector: ', nor ', ) end