Class: SpreeEssentials::Generators::EssentialsBase

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

Direct Known Subclasses

PressGenerator

Class Method Summary collapse

Class Method Details

.countObject



7
8
9
10
# File 'lib/generators/essentials_base.rb', line 7

def self.count
  @count ||= 0
  (@count += 1) * 3
end

.new_migration_numberObject



12
13
14
# File 'lib/generators/essentials_base.rb', line 12

def self.new_migration_number
  (Time.new.utc + self.count).strftime("%Y%m%d%H%M%S")
end

.next_migration_number(path) ⇒ Object



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

def self.next_migration_number(path)
  @time ||= Time.new.utc
  if ActiveRecord::Base.timestamped_migrations
    files = Dir.entries(Rails.root.join("db/migrate"))
    migration = new_migration_number
    while files.join.include?(migration)
      migration = new_migration_number
    end
    migration
  else
    "%.3d" % (current_migration_number(dirname) + 1)
  end
end