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


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 28

def create_initializer
  initializer "acl9.rb" do
    "# See https://github.com/be9/acl9#configuration for details\n#\n# Acl9.config.merge!(\n#   :default_role_class_name    => 'Role',\n#   :default_subject_class_name => 'User',\n#   :default_subject_method     => :current_user,\n#   :default_association_name   => :role_objects,\n#   :protect_global_roles       => true,\n#   :normalize_role_names       => true,\n# )\n".strip_heredoc
  end
end

#create_migrationObject


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

def create_migration
  next_migration_number = self.class.next_migration_number( File.expand_path( '../db/migrate', __FILE__))
  template "create_role_tables.rb", "db/migrate/#{next_migration_number}_create_#{role_name}_tables.rb"
end

#create_modelsObject


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

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