Sha256: 3af1c35d0a1f4ed546f87be12020f29032766166c0466517263e0a9f65c6e099

Contents?: true

Size: 384 Bytes

Versions: 7

Compression:

Stored size: 384 Bytes

Contents

# frozen_string_literal: true

module EacRailsUtils
  class ImmutableValidator < ActiveModel::EachValidator
    DEFAULT_MESSAGE = 'cannot be changed'

    def validate_each(record, attribute, _value)
      return if record.new_record?
      return unless record.send("#{attribute}_changed?")

      record.errors[attribute] << (options[:message] || DEFAULT_MESSAGE)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
eac_rails_utils-0.22.2 app/validators/eac_rails_utils/immutable_validator.rb
eac_rails_utils-0.22.1 app/validators/eac_rails_utils/immutable_validator.rb
eac_rails_utils-0.22.0 app/validators/eac_rails_utils/immutable_validator.rb
eac_rails_utils-0.21.0 app/validators/eac_rails_utils/immutable_validator.rb
eac_rails_utils-0.20.0 app/validators/eac_rails_utils/immutable_validator.rb
eac_rails_utils-0.19.0 app/validators/eac_rails_utils/immutable_validator.rb
eac_rails_utils-0.18.0 app/validators/eac_rails_utils/immutable_validator.rb