Sha256: 2db87d349eb750c3893b9bd3bb4ecc28ddd5e53af4e041fbd3a2eaa52eaf1bdf

Contents?: true

Size: 1013 Bytes

Versions: 2

Compression:

Stored size: 1013 Bytes

Contents

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

module J7W1
  class MigrationGenerator < Rails::Generators::Base
    include Rails::Generators::Migration

    def self.orm
      Rails::Generators.options[:rails][:orm]
    end

    def self.source_root
      File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.class.eql?(String)) )
    end

    def self.orm_has_migration?
      [:active_record].include? orm
    end

    def self.next_migration_number(dirname)
      if ActiveRecord::Base.timestamped_migrations
        migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
        migration_number += 1
        migration_number.to_s
      else
        "%.3d" % (current_migration_number(dirname) + 1)
      end
    end

    desc "This generator provides the tables which the J7W1 uses."
    def create_migration_file
      if self.class.orm_has_migration?
        migration_template 'migration.rb', 'db/migrate/j7w1_application_devices'
      end
    end
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
j7w1-0.0.2 lib/generators/j7_w1/migration/migration_generator.rb
j7w1-0.0.1 lib/generators/j7_w1/migration/migration_generator.rb