Class: DoubleAuthEngine::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(path) ⇒ Object



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

def self.next_migration_number(path)
  unless @prev_migration_nr
    @prev_migration_nr = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
  else
    @prev_migration_nr += 1
  end
  @prev_migration_nr.to_s
end

.source_rootObject



7
8
9
# File 'lib/double_auth_engine/generators/double_auth_engine/install_generator.rb', line 7

def self.source_root
  @source_root ||= File.join(File.dirname(__FILE__), 'templates')
end

Instance Method Details

#add_rolesObject

Passing a block to append_to_file would not format nicely, which is why I opted for separate append statements. Don’t judge.



42
43
44
45
46
# File 'lib/double_auth_engine/generators/double_auth_engine/install_generator.rb', line 42

def add_roles
  append_to_file "db/seeds.rb", "if Role.all.empty?\n"
  append_to_file "db/seeds.rb", "\tRole.create(:name => 'admin')\n"
  append_to_file "db/seeds.rb", "end\n"
end

#create_authorization_fileObject



30
31
32
# File 'lib/double_auth_engine/generators/double_auth_engine/install_generator.rb', line 30

def create_authorization_file
  copy_file "authorization_rules.rb", "config/authorization_rules.rb"
end

#create_initializer_fileObject



26
27
28
# File 'lib/double_auth_engine/generators/double_auth_engine/install_generator.rb', line 26

def create_initializer_file
  copy_file "setup_mail_initializer.rb", "config/initializers/setup_mail.rb"
end

#create_migration_filesObject



20
21
22
23
24
# File 'lib/double_auth_engine/generators/double_auth_engine/install_generator.rb', line 20

def create_migration_files
  migration_template "user_migration.rb", "db/migrate/create_users.rb"
  migration_template "role_migration.rb", "db/migrate/create_roles.rb"
  migration_template "assignment_migration.rb", "db/migrate/create_assignments.rb"
end

#update_application_controllerObject



34
35
36
37
38
# File 'lib/double_auth_engine/generators/double_auth_engine/install_generator.rb', line 34

def update_application_controller
  insert_into_file "app/controllers/application_controller.rb", :after => "class ApplicationController < ActionController::Base\n" do
    "\tinclude DoubleAuthEngine::ApplicationControllerMixin\n"
  end
end