Sha256: b2212437224e1a22054ed0bbc5044f9ffd43544b64762c3eaeb3985c709e3c24

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

require 'diesel/generators/base'
require 'rails/generators/active_record/migration'

module Diesel
  module Generators
    class InstallBase < Diesel::Generators::Base

      include Rails::Generators::Migration
      extend ActiveRecord::Generators::Migration

      def generate_migrations
        migrations.each do |source_file|
          name = migration_name(source_file)
          unless migration_exists?(name)
            migration_template source_file, "db/migrate/#{name}"
          end
        end
      end

      def self.inherited(generator)
        super
        generator.desc %{Generate configuration, migration, and other essential files.}
      end

      private

      def migrations
        files_within_root(".", "db/migrate/*.rb")
      end

      def migration_exists?(name)
        existing_migrations.include?(name)
      end

      def existing_migrations
        @existing_migrations ||= Dir.glob("db/migrate/*.rb").map do |file|
          migration_name(file)
        end
      end

      def migration_name(file)
        file.sub(%r{^.*(db/migrate/)(?:\d+_)?}, '')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
diesel-0.1.5 lib/diesel/generators/install_base.rb