class Postburner::InstallGenerator

Public Class Methods

next_migration_number(dirname) click to toggle source
# File lib/generators/postburner/install/install_generator.rb, line 9
def self.next_migration_number(dirname)
  timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
  stem = timestamp[0..-3]
  regexp = Regexp.new("^(#{stem})(\\d\\d)_")
  timestamps = Dir[File.join(dirname, '*.rb')].map { |name|
    match = regexp.match(File.basename(name, File.extname(name)))
    match ? match[2].to_i : nil
  }.reject(&:nil?)
  _max = timestamps.max || timestamp[-2..-1].to_i
  _next = _max + 1
  raise "MISSING NEXT" if _next.blank?
  migration_number = "#{stem}#{_next}"
  if migration_number.length != 14
    raise "INCORRECT LENGTH stem=#{stem} _next=#{_next} _max=#{_max}"
  end
  migration_number
end

Public Instance Methods

install_migrations() click to toggle source
# File lib/generators/postburner/install/install_generator.rb, line 5
def install_migrations
  install_migration! 'create_postburner_jobs'
end

Private Instance Methods

install_migration!(filename) click to toggle source
# File lib/generators/postburner/install/install_generator.rb, line 29
def install_migration!(filename)
  migrate_path = File.join(Rails.root, "db/migrate")

  if self.class.migration_exists?(migrate_path, "#{filename}")
    say_status "skipped", "#{filename}.rb migration already exists"
  else
    migration_template(
      "migrations/#{filename}.rb.erb",
      File.join(migrate_path, "#{filename}.rb"),
      migration_version: migration_version,
    )
  end
end
migration_version() click to toggle source
# File lib/generators/postburner/install/install_generator.rb, line 43
def migration_version
  "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
end