Class: Postburner::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
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



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/generators/postburner/install/install_generator.rb', line 9

def self.next_migration_number(dirname)
  timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
  stem = timestamp[0..-3]
  regexp = Regexp.new("^(#{stem})(\\d\\d)_")
  timestamps = 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 = timestamps.max || timestamp[-2..-1].to_i
  _next = _max + 1
  raise "MISSING NEXT" if _next.blank?
  migration_number = "#{stem}#{_next}"
  if migration_number.length != 14
    raise "INCORRECT LENGTH stem=#{stem} _next=#{_next} _max=#{_max}"
  end
  migration_number
end

Instance Method Details

#install_migrationsObject



5
6
7
# File 'lib/generators/postburner/install/install_generator.rb', line 5

def install_migrations
  install_migration! 'create_postburner_jobs'
end