Sha256: 5b5959601951cf7e453767f44c19c0074bf91909ab8e7b33086f21ff4a568558

Contents?: true

Size: 272 Bytes

Versions: 2

Compression:

Stored size: 272 Bytes

Contents

class ImmutableValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, _value)
    return if record.new_record?
    return unless record.public_send("#{attribute}_changed?")
    record.errors.add(attribute, options[:message] || :immutable)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activemodel-immutable_validator-0.0.2 lib/immutable_validator.rb
activemodel-immutable_validator-0.0.1 lib/immutable_validator.rb