Sha256: 7381f1e349609bec73d01c0ab361e2f6fd6c5a3e96fe3efb25641278c9a2bc28

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require 'rails/generators/migration'
require 'rails/generators/active_record'

module AsyncActiveJob
  class ActiveRecordGenerator < Rails::Generators::Base
    include Rails::Generators::Migration

    source_paths << File.join(__dir__, 'templates')

    def create_migration_file
      migration_template 'migration.rb.erb',
                         'db/migrate/create_async_active_jobs.rb',
                         migration_version: migration_version
    end

    def self.next_migration_number(dirname)
      ActiveRecord::Generators::Base.next_migration_number dirname
    end

    private

    def migration_version
      "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]" if ActiveRecord::VERSION::MAJOR >= 5
    end

    def next_migration_number(dirname)
      next_migration_number = current_migration_number(dirname) + 1
      if ActiveRecord::Base.timestamped_migrations
        [Time.now.utc.strftime('%Y%m%d%H%M%S'), format('%.14d', next_migration_number)].max
      else
        format('%.3d', next_migration_number)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
async_active_job-0.1.0 lib/generators/async_active_job/active_record_generator.rb