Sha256: 2f16220f443e0eb4d761dedb67879b208757d2b8b31f085c17571902f95dccb2

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 KB

Contents

require 'rails/generators'
module ConfigScripts
  # This class provides a generator for creating the migrations that we need to
  # use this gem.
  class MigrationsGenerator < Rails::Generators::Base
    include Rails::Generators::Migration
    source_root File.expand_path('../../../../templates', __FILE__)

    # This generator creates the migrations that we need for the gem.
    def create_migrations
      copy_migration 'create_config_scripts'
    end

    # This method gets the number for the next migration created by this
    # generator.
    #
    # @param [String] dirname
    #   The name of the directory in which we are creating the migrations.
    #
    # We use the current timestamp.
    def self.next_migration_number(dirname)
      Time.now.to_s(:number)
    end

    protected

    # This method copies a migration from our template directory to the app's
    # migrations directory.
    #
    # @param [String] filename
    #   The name of the file in the templates directory.
    def copy_migration(filename)
      migration_template "#{filename}_migration.rb", "db/migrate/#{filename}.rb"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
config_scripts-0.4.7 lib/config_scripts/generators/migrations.rb
config_scripts-0.4.6 lib/config_scripts/generators/migrations.rb
config_scripts-0.4.5 lib/config_scripts/generators/migrations.rb
config_scripts-0.4.4 lib/config_scripts/generators/migrations.rb
config_scripts-0.4.3 lib/config_scripts/generators/migrations.rb
config_scripts-0.4.2 lib/config_scripts/generators/migrations.rb
config_scripts-0.4.1 lib/config_scripts/generators/migrations.rb