Sha256: 210d3885c380fc7408997956ffb64360db4b72886cd7694ac023f6251687804d

Contents?: true

Size: 560 Bytes

Versions: 5

Compression:

Stored size: 560 Bytes

Contents

# frozen_string_literal: true

# @private
# Ensure that an attribute is different from another one
class PGTrunk::DifferenceValidator < ActiveModel::EachValidator
  def validate_each(record, attribute, value)
    another_name = options.fetch(:from)
    another_value = record.send(another_name).presence

    case another_value
    when PGTrunk::QualifiedName
      return unless value.maybe_eq?(another_value)
    else
      return unless value == another_value
    end

    record.errors.add attribute, "must be different from the #{another_name}"
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pg_trunk-0.2.0 lib/pg_trunk/core/validators/difference_validator.rb
pg_trunk-0.1.3 lib/pg_trunk/core/validators/difference_validator.rb
pg_trunk-0.1.2 lib/pg_trunk/core/validators/difference_validator.rb
pg_trunk-0.1.1 lib/pg_trunk/core/validators/difference_validator.rb
pg_trunk-0.1.0 lib/pg_trunk/core/validators/difference_validator.rb