Sha256: 41a3e0e723bbc483f3829738534f428185a95805adaf9b79ba517cd9177145c1

Contents?: true

Size: 1.28 KB

Versions: 105

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true
require 'rails/generators'
require 'rails/generators/active_record'

module GoodJob
  #
  # Rails generator used for updating GoodJob in a Rails application.
  # Run it with +bin/rails g good_job:update+ in your console.
  #
  class UpdateGenerator < Rails::Generators::Base
    include ActiveRecord::Generators::Migration

    TEMPLATES = File.join(File.dirname(__FILE__), "templates/update")
    source_paths << TEMPLATES

    class_option :database, type: :string, aliases: %i(--db), desc: "The database for your migration. By default, the current environment's primary database is used."

    # Generates incremental migration files unless they already exist.
    # All migrations should be idempotent e.g. +add_index+ is guarded with +if_index_exists?+
    def update_migration_files
      migration_templates = Dir.children(File.join(TEMPLATES, 'migrations')).sort
      migration_templates.each do |template_file|
        destination_file = template_file.match(/^\d*_(.*\.rb)/)[1] # 01_create_good_jobs.rb.erb => create_good_jobs.rb
        migration_template "migrations/#{template_file}", File.join(db_migrate_path, destination_file), skip: true
      end
    end

    private

    def migration_version
      "[#{ActiveRecord::VERSION::STRING.to_f}]"
    end
  end
end

Version data entries

105 entries across 105 versions & 1 rubygems

Version Path
good_job-3.15.14 lib/generators/good_job/update_generator.rb
good_job-3.15.13 lib/generators/good_job/update_generator.rb
good_job-3.15.12 lib/generators/good_job/update_generator.rb
good_job-3.15.11 lib/generators/good_job/update_generator.rb
good_job-3.15.10 lib/generators/good_job/update_generator.rb
good_job-3.15.9 lib/generators/good_job/update_generator.rb
good_job-3.15.8 lib/generators/good_job/update_generator.rb
good_job-3.15.7 lib/generators/good_job/update_generator.rb
good_job-3.15.6 lib/generators/good_job/update_generator.rb
good_job-3.15.5 lib/generators/good_job/update_generator.rb
good_job-3.15.4 lib/generators/good_job/update_generator.rb
good_job-3.15.3 lib/generators/good_job/update_generator.rb
good_job-3.15.2 lib/generators/good_job/update_generator.rb
good_job-3.15.1 lib/generators/good_job/update_generator.rb
good_job-3.15.0 lib/generators/good_job/update_generator.rb
good_job-3.14.2 lib/generators/good_job/update_generator.rb
good_job-3.14.1 lib/generators/good_job/update_generator.rb
good_job-3.14.0 lib/generators/good_job/update_generator.rb
good_job-3.13.0 lib/generators/good_job/update_generator.rb
good_job-3.12.8 lib/generators/good_job/update_generator.rb