Class: Emailbutler::Generators::ActiveRecordGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.migration_versionObject



17
18
19
# File 'lib/generators/emailbutler/active_record_generator.rb', line 17

def self.migration_version
  "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" if requires_migration_number?
end

.next_migration_number(dirname) ⇒ Object



13
14
15
# File 'lib/generators/emailbutler/active_record_generator.rb', line 13

def self.next_migration_number(dirname)
  ::ActiveRecord::Generators::Base.next_migration_number(dirname)
end

.requires_migration_number?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/generators/emailbutler/active_record_generator.rb', line 21

def self.requires_migration_number?
  Rails::VERSION::MAJOR.to_i >= 5
end

Instance Method Details

#create_migration_fileObject



25
26
27
28
29
30
# File 'lib/generators/emailbutler/active_record_generator.rb', line 25

def create_migration_file
  options = {
    migration_version: migration_version
  }
  migration_template 'migration.erb', 'db/migrate/create_emailbutler_tables.rb', options
end

#migration_versionObject



32
33
34
# File 'lib/generators/emailbutler/active_record_generator.rb', line 32

def migration_version
  self.class.migration_version
end