Sha256: dbb9ea45b7aa62857a44076f5a85460c202264d4b55c2ef5ef3fbf65c7f352b8

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

require "rails/generators"
require "rails/generators/active_record"

class AcidicJobGenerator < ActiveRecord::Generators::Base
  # ActiveRecord::Generators::Base inherits from Rails::Generators::NamedBase
  # which requires a NAME parameter for the new table name.
  # Our generator always uses "acidic_job_runs", so we just set a random name here.
  argument :name, type: :string, default: "random_name"

  source_root File.expand_path("templates", __dir__)

  def self.next_migration_number(_path)
    if instance_variable_defined?("@prev_migration_nr") # :nocov:
      @prev_migration_nr += 1
    else
      @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
    end

    @prev_migration_nr.to_s
  end

  # Copies the migration template to db/migrate.
  def copy_acidic_job_runs_migration_files
    migration_template "create_acidic_job_runs_migration.rb.erb",
                       "db/migrate/create_acidic_job_runs.rb"
  end

  protected

  def migration_class
    ActiveRecord::Migration["#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
acidic_job-1.0.0.pre2 lib/generators/acidic_job_generator.rb
acidic_job-1.0.0.pre1 lib/generators/acidic_job_generator.rb