Class: RoleFu::Generators::RoleFuGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- RoleFu::Generators::RoleFuGenerator
- Defined in:
- lib/generators/role_fu/role_fu_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.banner ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/generators/role_fu/role_fu_generator.rb', line 15 def self. "bin/rails generate role_fu [Role] [User] [options]\n\n" \ "Generates the Role model and the assignment join model, then links them to the User model.\n" \ " Usage:\n" \ " rails g role_fu # Generates 'Role' and links to 'User' (default)\n" \ " rails g role_fu Group # Generates 'Group' and links to 'User'\n" \ " rails g role_fu Group Account # Generates 'Group' and links to 'Account'" end |
Instance Method Details
#copy_role_fu_migration ⇒ Object
35 36 37 |
# File 'lib/generators/role_fu/role_fu_generator.rb', line 35 def copy_role_fu_migration migration_template "migration.rb.erb", "db/migrate/role_fu_create_#{table_name}.rb" end |
#generate_models ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/generators/role_fu/role_fu_generator.rb', line 26 def generate_models # Generate Role model template "role.rb.erb", "app/models/#{name.underscore}.rb" # Generate RoleAssignment model assignment_name = "#{name}Assignment" template "role_assignment.rb.erb", "app/models/#{assignment_name.underscore}.rb" end |
#inject_role_fu_into_user_model ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/generators/role_fu/role_fu_generator.rb', line 39 def inject_role_fu_into_user_model user_path = "app/models/#{user_cname.underscore}.rb" if File.exist?(user_path) inject_into_class(user_path, user_cname.constantize) do " include RoleFu::Roleable\n" end else say "User model #{user_cname} not found at #{user_path}. Please add 'include RoleFu::Roleable' manually." end end |