Class: Acl9::SetupGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
lib/generators/acl9/setup/setup_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_initializerObject


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/generators/acl9/setup/setup_generator.rb', line 27

def create_initializer
  initializer "acl9.rb" do
    <<-RUBY.strip_heredoc
    # See https://github.com/be9/acl9#configuration for details
    #
    # Acl9.configure do |c|
    #   c.default_role_class_name = 'Role'
    #   c.default_subject_class_name = 'User'
    #   c.default_subject_method     = :current_user
    #   c.default_association_name   = :role_objects
    #   c.default_join_table_name    = nil
    #   c.protect_global_roles       = true
    #   c.normalize_role_names       = true
    # end
    RUBY
  end
end

#create_migration_fileObject


13
14
15
# File 'lib/generators/acl9/setup/setup_generator.rb', line 13

def create_migration_file
  migration_template "create_role_tables.rb", File.join(db_migrate_path, "create_#{role_name}_tables.rb")
end

#create_modelsObject


17
18
19
20
21
22
23
24
25
# File 'lib/generators/acl9/setup/setup_generator.rb', line 17

def create_models
  template "role.rb", "app/models/#{role_name}.rb"

  objects.each do |object|
    my_inject "app/models/#{object}.rb", object.classify, "  #{object_helper}\n"
  end

  my_inject "app/models/#{subject_name}.rb", subject_class_name, "  #{subject_helper}\n"
end