Sha256: ecf42a78be1413b17552db1521a89dacbaa3c7f3561f159f99f505b4bbe9a80a

Contents?: true

Size: 605 Bytes

Versions: 3

Compression:

Stored size: 605 Bytes

Contents

class PersonWithValidator
  include ActiveModel::Validations

  class PresenceValidator < ActiveModel::EachValidator
    def validate_each(record, attribute, value)
      record.errors[attribute] << "Local validator#{options[:custom]}" if value.blank?
    end
  end

  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

  attr_accessor :title, :karma
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
activejob-lock-0.0.2 rails/activemodel/test/models/person_with_validator.rb
activejob-lock-0.0.1 rails/activemodel/test/models/person_with_validator.rb
mass_assignment_with_multiple_roles-0.0.1 test/models/person_with_validator.rb