2017-07-16 13:11:16 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2010-01-07 12:44:35 -05:00
|
|
|
class PersonWithValidator
|
|
|
|
include ActiveModel::Validations
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2010-01-07 12:44:35 -05:00
|
|
|
class PresenceValidator < ActiveModel::EachValidator
|
|
|
|
def validate_each(record, attribute, value)
|
2018-03-31 10:42:40 -04:00
|
|
|
record.errors.add(attribute, message: "Local validator#{options[:custom]}") if value.blank?
|
2010-01-07 12:44:35 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-20 21:35:41 -04:00
|
|
|
class LikeValidator < ActiveModel::EachValidator
|
|
|
|
def initialize(options)
|
|
|
|
@with = options[:with]
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_each(record, attribute, value)
|
|
|
|
unless value[@with]
|
|
|
|
record.errors.add attribute, "does not appear to be like #{@with}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-07 12:44:35 -05:00
|
|
|
attr_accessor :title, :karma
|
|
|
|
end
|