Sha256: 4b753aed38d39cfe3a8730d27e95d079004ed92a004df4c48d129c8d97abdeb9

Contents?: true

Size: 443 Bytes

Versions: 8

Compression:

Stored size: 443 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) # rubocop:disable Rails/DeprecatedActiveModelErrorsMethods
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
eac_rails_utils-0.25.0 app/validators/eac_rails_utils/immutable_validator.rb
eac_rails_utils-0.24.0 app/validators/eac_rails_utils/immutable_validator.rb
eac_rails_utils-0.23.4 app/validators/eac_rails_utils/immutable_validator.rb
eac_rails_utils-0.23.3 app/validators/eac_rails_utils/immutable_validator.rb
eac_rails_utils-0.23.2 app/validators/eac_rails_utils/immutable_validator.rb
eac_rails_utils-0.23.1 app/validators/eac_rails_utils/immutable_validator.rb
eac_rails_utils-0.23.0 app/validators/eac_rails_utils/immutable_validator.rb
eac_rails_utils-0.22.3 app/validators/eac_rails_utils/immutable_validator.rb