Class: DlJusyoJp::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/dl_jusyo_jp/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



9
10
11
# File 'lib/generators/dl_jusyo_jp/install_generator.rb', line 9

def self.source_root
  File.expand_path("../templates", __FILE__)
end

Instance Method Details

#copy_initializerObject



13
14
15
# File 'lib/generators/dl_jusyo_jp/install_generator.rb', line 13

def copy_initializer
  template '../templates/initializers/dl_jusyo_jp.rb', 'config/initializers/dl_jusyo_jp.rb'
end

#create_migrationsObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/dl_jusyo_jp/install_generator.rb', line 17

def create_migrations
  Dir["#{self.class.source_root}/migrations/*.rb"].sort.each do |filepath|
    name = File.basename(filepath)
    to_path = 'db/migrate'
    # TODO: something wrong...
    if Dir.glob("#{to_path}/[0-9]*_*.rb").grep(/\d+_#{name}$/).blank?
      template("migrations/#{name}", "#{to_path}/#{Time.zone.now.strftime('%Y%m%d%H%M%S')}_#{name}")
    end
  end
end