Class: Truefactor::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



8
9
10
# File 'lib/generators/truefactor/install_generator.rb', line 8

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

Instance Method Details

#add_truefactor_migrationObject



20
21
22
# File 'lib/generators/truefactor/install_generator.rb', line 20

def add_truefactor_migration
  migration_template "migration.rb", "db/migrate/add_truefactor_to_#{table_name}.rb"
end

#add_truefactor_routeObject



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

def add_truefactor_route
  route "get '/truefactor', to: 'application#truefactor'"
end

#copy_initializerObject



43
44
45
# File 'lib/generators/truefactor/install_generator.rb', line 43

def copy_initializer
  template "truefactor.rb", "config/initializers/truefactor.rb"
end

#truefactorize_controllerObject



37
38
39
40
41
# File 'lib/generators/truefactor/install_generator.rb', line 37

def truefactorize_controller
  content = "  truefactorize\n"
  controller_path = File.join("app", "controllers", "application_controller.rb")
  inject_into_class(controller_path, 'ApplicationController', content)
end

#truefactorize_modelObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/generators/truefactor/install_generator.rb', line 24

def truefactorize_model
  content = "  truefactorize\n"
  class_path =
    if namespaced?
      class_name.to_s.split("::")
    else
      [class_name]
    end

  model_path = File.join("app", "models", "#{file_path}.rb")
  inject_into_class(model_path, class_path.last, content)
end