Sha256: cf2583930ebbe6dc901c40c1d32116ace1f281ff23a14377f563815175dc73f1

Contents?: true

Size: 280 Bytes

Versions: 1

Compression:

Stored size: 280 Bytes

Contents

module Papercat
  class UniquenessValidator < ActiveModel::Validator
    def validate(record)
      found = record.class.get(options[:key] => record.public_send(options[:key])).first
      record.errors.add options[:key], :taken if found && found.id != record.id
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
papercat-0.0.2 lib/papercat/uniqueness_validator.rb