Class: ActiveModel::Validations::ExistenceValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::ExistenceValidator
- Defined in:
- lib/dekiru/validators/existence.rb
Instance Method Summary collapse
Instance Method Details
#exists?(record, value) ⇒ Boolean
18 19 20 21 22 23 24 |
# File 'lib/dekiru/validators/existence.rb', line 18 def exists?(record, value) unless [:in].respond_to?(:call) raise ArgumentError, '`in` option should be proc' end collection = record.instance_exec(&[:in]) collection.exists?(value) end |
#validate_each(record, attribute, value) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/dekiru/validators/existence.rb', line 10 def validate_each(record, attribute, value) ActiveSupport::Deprecation.warn('`ExistenceValidator` is deprecated and will be removed in v0.5. Please use `inclusion: { in: xx }` instead.') unless exists?(record, value) record.errors.add(attribute, :existence, **.except(:in).merge!(value: value)) end end |