Sha256: c253ec7f5a205fcbd1a07eccd87016f2d2cc08f55ad1e9400a1f32ddb6342822

Contents?: true

Size: 1.1 KB

Versions: 10

Compression:

Stored size: 1.1 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 Rails::Generators::Migration

    class << self
      delegate :next_migration_number, to: ActiveRecord::Generators::Base
    end

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

    # 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}", "db/migrate/#{destination_file}", skip: true
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
good_job-2.0.1 lib/generators/good_job/update_generator.rb
good_job-2.0.0 lib/generators/good_job/update_generator.rb
good_job-1.99.0 lib/generators/good_job/update_generator.rb
good_job-1.13.2 lib/generators/good_job/update_generator.rb
good_job-1.13.1 lib/generators/good_job/update_generator.rb
good_job-1.13.0 lib/generators/good_job/update_generator.rb
good_job-1.12.2 lib/generators/good_job/update_generator.rb
good_job-1.12.1 lib/generators/good_job/update_generator.rb
good_job-1.12.0 lib/generators/good_job/update_generator.rb
good_job-1.11.3 lib/generators/good_job/update_generator.rb