class Nandi::Validation::AddReferenceValidator

Attributes

instruction[R]

Public Class Methods

call(instruction) click to toggle source
# File lib/nandi/validation/add_reference_validator.rb, line 10
def self.call(instruction)
  new(instruction).call
end
new(instruction) click to toggle source
# File lib/nandi/validation/add_reference_validator.rb, line 14
def initialize(instruction)
  @instruction = instruction
end

Public Instance Methods

call() click to toggle source
# File lib/nandi/validation/add_reference_validator.rb, line 18
def call
  foreign_key = instruction.extra_args.fetch(:foreign_key, false)
  index = instruction.extra_args.fetch(:index, false)

  collect_errors(
    assert(
      !foreign_key,
      foreign_key_message,
    ),
    assert(
      !index,
      index_message,
    ),
  )
end

Private Instance Methods

foreign_key_message() click to toggle source
# File lib/nandi/validation/add_reference_validator.rb, line 41
def foreign_key_message
  "Adding a foreign key constraint must be done in two separate migrations. " \
    "Use the `add_foreign_key` and `validate_foreign_key` methods, or the " \
    "nandi:foreign_key generator, to do this."
end
index_message() click to toggle source
# File lib/nandi/validation/add_reference_validator.rb, line 36
def index_message
  "Indexing a reference column on creation can make the table unavailable." \
    "Use the `add_index` method in a separate migration to index the column."
end