Class: Deimos::Generators::DbBackendGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Extended by:
ActiveRecord::Generators::Migration
Includes:
ActiveRecord::Generators::Migration, Rails::Generators::Migration
Defined in:
lib/generators/deimos/db_backend_generator.rb

Overview

Generate the database backend migration.

Instance Method Summary collapse

Instance Method Details

#db_migrate_pathString

Returns:

  • (String)


27
28
29
30
31
32
33
34
# File 'lib/generators/deimos/db_backend_generator.rb', line 27

def db_migrate_path
  if defined?(Rails.application) && Rails.application
    paths = Rails.application.config.paths['db/migrate']
    paths.respond_to?(:to_ary) ? paths.to_ary.first : paths.to_a.first
  else
    'db/migrate'
  end
end

#generateObject

Main method to create all the necessary files



37
38
39
40
41
42
43
44
45
# File 'lib/generators/deimos/db_backend_generator.rb', line 37

def generate
  if Rails.version < '4'
    migration_template('rails3_migration',
                       "#{db_migrate_path}/create_db_backend.rb")
  else
    migration_template('migration',
                       "#{db_migrate_path}/create_db_backend.rb")
  end
end

#migration_versionString

Returns:

  • (String)


20
21
22
23
24
# File 'lib/generators/deimos/db_backend_generator.rb', line 20

def migration_version
  "[#{ActiveRecord::Migration.current_version}]"
rescue StandardError
  ''
end