Class: Activa::Generators::InstallGenerator

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

Instance Method Summary collapse

Instance Method Details

#add_activa_initializerObject



60
61
62
63
64
65
66
67
68
# File 'lib/generators/activa/install_generator.rb', line 60

def add_activa_initializer
  path = "#{Rails.root}/config/initializers/activa.rb"
  if File.exists?(path)
    puts "Skipping config/initializers/activa.rb creation, as file already exists!"
  else
    puts "Adding activa initializer (config/initializers/activa.rb)..."
    template "initializer.rb", path
  end
end

#determine_current_user_helperObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/generators/activa/install_generator.rb', line 35

def determine_current_user_helper
  if options["current-user-helper"]
    current_user_helper = options["current-user-helper"]
  else
    current_user_helper = ask("What is the current_user helper called in your app? [current_user]")
  end

  current_user_helper = :current_user if current_user_helper.blank?
  puts "Defining activa_user method inside ApplicationController..."

  activa_user_method = <<-CONTENT.gsub(/^ {8}/, '')
    def activa_user
      #{current_user_helper}
    end

    helper_method :activa_user

  CONTENT

  inject_into_file("#{Rails.root}/app/controllers/application_controller.rb",
                   activa_user_method,
                   :after => "ActionController::Base\n")

end

#determine_user_classObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/generators/activa/install_generator.rb', line 20

def determine_user_class
  # Is there a cleaner way to do this?
  if options["user-class"]
    @user_class = options["user-class"]
  else
    @user_class = ask("What is your user class called? [User]")
  end

  if @user_class.blank?
    @user_class = 'User'
  else
    @user_class = @user_class
  end
end

#finishedObject



84
85
86
87
88
# File 'lib/generators/activa/install_generator.rb', line 84

def finished
  output = "\n\n" + ("*" * 53)
  output += %Q{\nDone! Activa has been successfully installed!}
  puts output
end

#install_migrationsObject



13
14
15
16
17
18
# File 'lib/generators/activa/install_generator.rb', line 13

def install_migrations
  puts "Copying over Activa migrations..."
  Dir.chdir(Rails.root) do
    `rake activa:install:migrations`
  end
end

#mount_engineObject



77
78
79
80
81
82
# File 'lib/generators/activa/install_generator.rb', line 77

def mount_engine
  puts "Mounting Activa::Engine at \"/activa\" in config/routes.rb..."
  insert_into_file("#{Rails.root}/config/routes.rb", :after => /routes.draw.do\n/) do
    %Q{  mount Activa::Engine, :at => "/activa"\n}
  end
end

#run_migrationsObject



70
71
72
73
74
75
# File 'lib/generators/activa/install_generator.rb', line 70

def run_migrations
  unless options["no-migrate"]
    puts "Running rake db:migrate"
    `rake db:migrate`
  end
end