Module: ActiveModel::Validations::Clusivity
Do not use. This module is for internal use only.
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Instance Chain:
self,
ResolveValue
|
|
Defined in: | activemodel/lib/active_model/validations/clusivity.rb |
Constant Summary
-
ERROR_MESSAGE =
# File 'activemodel/lib/active_model/validations/clusivity.rb', line 11"An object with the method #include? or a proc, lambda or symbol is required, " \ "and must be supplied as the :in (or :within) option of the configuration hash"
Instance Method Summary
- #check_validity!
- #delimiter private
- #include?(record, value) ⇒ Boolean private
-
#inclusion_method(enumerable)
private
After Ruby 2.2,
Range#include?
on non-number-or-time-ish ranges checks all possible values in the range for equality, which is slower but more accurate.
ResolveValue
- Included
Instance Method Details
#check_validity!
[ GitHub ]# File 'activemodel/lib/active_model/validations/clusivity.rb', line 14
def check_validity! unless delimiter.respond_to?(:include?) || delimiter.respond_to?(:call) || delimiter.respond_to?(:to_sym) raise ArgumentError, ERROR_MESSAGE end end
#delimiter (private)
[ GitHub ]# File 'activemodel/lib/active_model/validations/clusivity.rb', line 31
def delimiter @delimiter ||= [:in] || [:within] end
#include?(record, value) ⇒ Boolean
(private)
# File 'activemodel/lib/active_model/validations/clusivity.rb', line 21
def include?(record, value) members = resolve_value(record, delimiter) if value.is_a?(Array) value.all? { |v| members.public_send(inclusion_method(members), v) } else members.public_send(inclusion_method(members), value) end end
#inclusion_method(enumerable) (private)
After Ruby 2.2, Range#include?
on non-number-or-time-ish ranges checks all possible values in the range for equality, which is slower but more accurate. Range#cover?
uses the previous logic of comparing a value with the range endpoints, which is fast but is only accurate on ::Numeric
, ::Time
, ::Date
, or ::DateTime
ranges.