Class: Tramway::Generators::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(path) ⇒ Object



16
17
18
19
# File 'lib/tramway/generators/install_generator.rb', line 16

def self.next_migration_number(path)
  next_migration_number = current_migration_number(path) + 1
  ActiveRecord::Migration.next_migration_number next_migration_number
end

Instance Method Details

#copy_initializerObject



21
22
23
24
25
26
27
28
29
# File 'lib/tramway/generators/install_generator.rb', line 21

def copy_initializer
  simple_form_files = %w[simple_form simple_form_bootstrap]
  simple_form_files.each do |file|
    copy_file(
      "/#{File.dirname __dir__}/generators/templates/initializers/#{file}.rb",
      "config/initializers/#{file}.rb"
    )
  end
end

#copy_migrationsObject



31
32
33
34
35
36
37
38
39
# File 'lib/tramway/generators/install_generator.rb', line 31

def copy_migrations
  migrations = %i[
    create_tramway_users
  ]

  migrations.each do |migration|
    migration_template "#{migration}.rb", "db/migrate/#{migration}.rb"
  end
end

#run_decorator_generatorsObject



41
42
43
44
45
46
47
48
# File 'lib/tramway/generators/install_generator.rb', line 41

def run_decorator_generators
  Tramway::Error.raise_error(:tramway, :generators, :install) unless Tramway.application.present?

  project = Tramway.application.name
  Tramway.available_models_for(project).map do |model|
    generate 'tramway:model', model.to_s, "--user-role=#{options[:user_role]}"
  end
end

#run_other_generatorsObject



12
13
14
# File 'lib/tramway/generators/install_generator.rb', line 12

def run_other_generators
  generate 'audited:install'
end