Class: DeforestGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/generators/deforest/deforest_generator.rb', line 31

def self.next_migration_number(dirname)
  if (rails5_and_up? && ActiveRecord.timestamped_migrations) || ActiveRecord::Base.timestamped_migrations
    Time.now.utc.strftime("%Y%m%d%H%M%S")
  else
    "%.3d" % (current_numeric_version(dirname) + 1)
  end
end

.rails5_and_up?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/generators/deforest/deforest_generator.rb', line 21

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

Instance Method Details

#copy_initializer_fileObject



13
14
15
16
17
18
19
# File 'lib/generators/deforest/deforest_generator.rb', line 13

def copy_initializer_file
  if DeforestGenerator.rails5_and_up? && Rails.autoloaders.zeitwerk_enabled?
    copy_file "zeitwerk_enabled_initializer.rb", "config/initializers/deforest.rb"
  else
    copy_file "classic_enabled_initializer.rb", "config/initializers/deforest.rb"
  end
end

#copy_migration_fileObject



9
10
11
# File 'lib/generators/deforest/deforest_generator.rb', line 9

def copy_migration_file
  migration_template "migration.rb", "db/migrate/create_deforest_logs.rb", migration_version: migration_version
end

#migration_versionObject



25
26
27
28
29
# File 'lib/generators/deforest/deforest_generator.rb', line 25

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