Class: ActiveRecord::Zuul::Generators::RoleSubjectGenerator
- Inherits:
-
Generators::Base
- Object
- Generators::Base
- ActiveRecord::Zuul::Generators::RoleSubjectGenerator
show all
- Includes:
- Zuul::Generators::OrmHelpers
- Defined in:
- lib/generators/zuul/role_subject_generator.rb
Instance Method Summary
collapse
#migration_exists?, #migration_path, #model_exists?, #model_path
Instance Method Details
#copy_role_subject_migration ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/generators/zuul/role_subject_generator.rb', line 21
def copy_role_subject_migration
attributes << Rails::Generators::GeneratedAttribute.new("#{role_model.to_s.underscore.singularize}_id", :integer)
attributes << Rails::Generators::GeneratedAttribute.new("#{subject_model.to_s.underscore.singularize}_id", :integer)
attributes << Rails::Generators::GeneratedAttribute.new("context_type", :string)
attributes << Rails::Generators::GeneratedAttribute.new("context_id", :integer)
if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(:role_subject, table_name))
migration_template "role_subject_existing.rb", "db/migrate/add_zuul_role_subject_to_#{table_name}"
else
migration_template "role_subject.rb", "db/migrate/zuul_role_subject_create_#{table_name}"
end
end
|
#generate_model ⇒ Object
34
35
36
|
# File 'lib/generators/zuul/role_subject_generator.rb', line 34
def generate_model
invoke "active_record:model", [name].concat(attributes.map {|attr| "#{attr.name}:#{attr.type}" }), :migration => false unless model_exists? && behavior == :invoke
end
|
#name ⇒ Object
17
18
19
|
# File 'lib/generators/zuul/role_subject_generator.rb', line 17
def name
[role_model, subject_model].sort.map(&:to_s).map(&:camelize).map(&:singularize).join("")
end
|