class Nandi::CheckConstraintGenerator

Attributes

add_check_constraint_name[R]
validate_check_constraint_name[R]

Public Instance Methods

add_check_constraint() click to toggle source
# File lib/generators/nandi/check_constraint/check_constraint_generator.rb, line 18
def add_check_constraint
  self.table = table.to_sym
  self.name = name.to_sym

  @add_check_constraint_name = "add_check_constraint_#{name}_on_#{table}"

  template(
    "add_check_constraint.rb",
    "#{base_path}/#{timestamp}_#{add_check_constraint_name}.rb",
  )
end
validate_check_constraint() click to toggle source
# File lib/generators/nandi/check_constraint/check_constraint_generator.rb, line 30
def validate_check_constraint
  self.table = table.to_sym
  self.name = name.to_sym

  @validate_check_constraint_name = "validate_check_constraint_#{name}_on_#{table}"

  template(
    "validate_check_constraint.rb",
    "#{base_path}/#{timestamp(1)}_#{validate_check_constraint_name}.rb",
  )
end

Private Instance Methods

base_path() click to toggle source
# File lib/generators/nandi/check_constraint/check_constraint_generator.rb, line 44
def base_path
  Nandi.config.migration_directory || "db/safe_migrations"
end
timestamp(offset = 0) click to toggle source
# File lib/generators/nandi/check_constraint/check_constraint_generator.rb, line 48
def timestamp(offset = 0)
  (Time.now.utc + offset).strftime("%Y%m%d%H%M%S")
end