Class: Postburner::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Postburner::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/postburner/install/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.next_migration_number(dirname) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/generators/postburner/install/install_generator.rb', line 22 def self.next_migration_number(dirname) = Time.now.utc.strftime("%Y%m%d%H%M%S") stem = [0..-3] regexp = Regexp.new("^(#{stem})(\\d\\d)_") = Dir[File.join(dirname, '*.rb')].map { |name| match = regexp.match(File.basename(name, File.extname(name))) match ? match[2].to_i : nil }.reject(&:nil?) _max = .max || [-2..-1].to_i _next = _max + 1 raise "MISSING NEXT" if _next.blank? # When seconds overflow past 99, roll forward by 1 minute and reset. if _next > 99 rolled = Time.parse("#{stem}00 UTC") + 60 stem = rolled.strftime('%Y%m%d%H%M') _next = 0 end "#{stem}#{_next.to_s.rjust(2, '0')}" end |
Instance Method Details
#copy_config_file ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/generators/postburner/install/install_generator.rb', line 12 def copy_config_file destination = "config/postburner.yml" if File.exist?(File.join(destination_root, destination)) say_status "skip", destination, :yellow else template "config/postburner.yml", destination end end |
#install_migrations ⇒ Object
7 8 9 10 |
# File 'lib/generators/postburner/install/install_generator.rb', line 7 def install_migrations install_migration! 'create_postburner_jobs' install_migration! 'create_postburner_schedules' end |