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 104
def initialize(attribute)
  super(attribute)
  @array = nil
  @range = nil
  @expected_message = nil
end

Public Instance Methods

description() click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 128
def description
  "ensure exclusion of #{@attribute} in #{inspect_message}"
end
in_array(array) click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 111
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 116
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 132
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
with_message(message) click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 123
def with_message(message)
  @expected_message = message if message
  self
end

Private Instance Methods

allows_higher_value() click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 157
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 153
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 147
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 165
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 161
def disallows_minimum_value
  disallows_value_of(@minimum, expected_message)
end
expected_message() click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 169
def expected_message
  @expected_message || :exclusion
end
inspect_message() click to toggle source
# File lib/shoulda/matchers/active_model/validate_exclusion_of_matcher.rb, line 173
def inspect_message
  if @range
    @range.inspect
  else
    @array.inspect
  end
end