Class: ActiveRecord::Generators::BestBoyGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/active_record/best_boy_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/generators/active_record/best_boy_generator.rb', line 7

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

Instance Method Details

#create_migration_fileObject



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

def create_migration_file
  %w( create_best_boy_events_table.rb
      add_event_source_to_best_boy_events_table.rb
      create_best_boy_reports.rb
    ).each do |migration_file|
    destination = "db/migrate/#{migration_file.sub(%r\.rb$\, '')}"
    if not self.class.migration_exists?(File.dirname(destination), File.basename(destination))
      migration_template migration_file, destination
    end
  end
end