Class: CommerceUnits::Generators::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

Define the next_migration_number method (necessary for the migration_template method to work) Stolen shamelessly from socery gem’s generators



12
13
14
15
16
17
18
19
# File 'lib/generators/commerce_units/install_generator.rb', line 12

def self.next_migration_number(dirname)
  if ActiveRecord::Base.timestamped_migrations
    sleep 1 # make sure each time we get a different timestamp
    Time.new.utc.strftime("%Y%m%d%H%M%S")
  else
    "%.3d" % (current_migration_number(dirname) + 1)
  end
end

Instance Method Details

#generate_migrationObject



21
22
23
# File 'lib/generators/commerce_units/install_generator.rb', line 21

def generate_migration
  migration_template "create_commerce_units_dimensions.rb.erb", "db/migrate/#{migration_file_name}"
end

#migration_class_nameObject



33
34
35
# File 'lib/generators/commerce_units/install_generator.rb', line 33

def migration_class_name
  migration_name.camelize
end

#migration_file_nameObject



29
30
31
# File 'lib/generators/commerce_units/install_generator.rb', line 29

def migration_file_name
  "#{migration_name}.rb"
end

#migration_nameObject



25
26
27
# File 'lib/generators/commerce_units/install_generator.rb', line 25

def migration_name
  "create_commerce_units_dimensions"
end