Class: ActiveRecord::Zuul::Generators::RoleGenerator
- Inherits:
-
Generators::Base
- Object
- Generators::Base
- ActiveRecord::Zuul::Generators::RoleGenerator
show all
- Includes:
- Zuul::Generators::OrmHelpers
- Defined in:
- lib/generators/zuul/role_generator.rb
Instance Method Summary
collapse
#migration_exists?, #migration_path, #model_exists?, #model_path
Instance Method Details
#copy_role_migration ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/generators/zuul/role_generator.rb', line 16
def copy_role_migration
if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(:role, table_name))
migration_template "role_existing.rb", "db/migrate/add_zuul_role_to_#{table_name}"
else
migration_template "role.rb", "db/migrate/zuul_role_create_#{table_name}"
end
end
|
#generate_model ⇒ Object
24
25
26
|
# File 'lib/generators/zuul/role_generator.rb', line 24
def generate_model
invoke "active_record:model", [name].concat(attributes.map {|attr| "#{attr.name}:#{attr.type}" }), :migration => false unless model_exists? && behavior == :invoke
end
|
#inject_role_content ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/generators/zuul/role_generator.rb', line 28
def inject_role_content
content = <<CONTENT
# Setup authorization for your role model
acts_as_authorization_role
CONTENT
class_path = if namespaced?
class_name.to_s.split("::")
else
[class_name]
end
indent_depth = class_path.size - 1
content = content.split("\n").map { |line| " " * indent_depth + line } .join("\n") << "\n"
inject_into_class(model_path, class_path.last, content) if model_exists?
end
|
#migration_data ⇒ Object
46
47
48
49
50
51
52
53
54
|
# File 'lib/generators/zuul/role_generator.rb', line 46
def migration_data
<<RUBY
## Authorization role columns
t.string :slug
t.integer :level
t.string :context_type
t.integer :context_id
RUBY
end
|