Class: ClearanceGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Defined in:
lib/rails/generators/clearance_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



8
9
10
# File 'lib/rails/generators/clearance_generator.rb', line 8

def self.source_root
  @_clearance_source_root ||= File.join(File.dirname(__FILE__), "clearance_templates")
end

Instance Method Details

#installObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/rails/generators/clearance_generator.rb', line 12

def install
  template "clearance.rb", "config/initializers/clearance.rb"

  inject_into_class "app/controllers/application_controller.rb", ApplicationController do
    "  include Clearance::Authentication\n"
  end

  user_model = "app/models/user.rb"
  if File.exists?(user_model)
    inject_into_class user_model, User do
      "include Clearance::User"
    end
  else
    template "user.rb", user_model
  end

  if File.exists?("spec")
    template "factories.rb", "spec/factories/clearance.rb"
  else
    template "factories.rb", "test/factories/clearance.rb"
  end

  migration_template "migrations/#{migration_source_name}.rb",
                     "db/migrate/clearance_#{migration_target_name}"

  #readme "README"
end