# File lib/active_model/validations/exclusion.rb, line 10 10: def check_validity! 11: unless [:include?, :call].any? { |method| delimiter.respond_to?(method) } 12: raise ArgumentError, ERROR_MESSAGE 13: end 14: end
# File lib/active_model/validations/exclusion.rb, line 16 16: def validate_each(record, attribute, value) 17: exclusions = delimiter.respond_to?(:call) ? delimiter.call(record) : delimiter 18: if exclusions.send(inclusion_method(exclusions), value) 19: record.errors.add(attribute, :exclusion, options.except(:in, :within).merge!(:value => value)) 20: end 21: end
# File lib/active_model/validations/exclusion.rb, line 25 25: def delimiter 26: @delimiter ||= options[:in] || options[:within] 27: end
In Ruby 1.9 Range#include? on non-numeric ranges checks all possible values in the range for equality, so it may be slow for large ranges. The new Range#cover? uses the previous logic of comparing a value with the range endpoints.
# File lib/active_model/validations/exclusion.rb, line 33 33: def inclusion_method(enumerable) 34: enumerable.is_a?(Range) ? :cover? : :include? 35: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.