Class: Deimos::Generators::DbPollerGenerator

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_poller_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_poller_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

#generatevoid

This method returns an undefined value.

Main method to create all the necessary files



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

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

#migration_versionString

Returns:

  • (String)


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

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