class DoubleAuthEngine::InstallGenerator

Public Class Methods

next_migration_number(path) click to toggle source
# 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_root() click to toggle source
# 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

Public Instance Methods

add_roles() click to toggle source

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

# 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_file() click to toggle source
# 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_file() click to toggle source
# 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_files() click to toggle source
# 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_controller() click to toggle source
# 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