Class: Rolify::Generators::RoleGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Rolify::Generators::RoleGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/rolify/role/role_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.next_migration_number(path) ⇒ Object
33 34 35 |
# File 'lib/generators/rolify/role/role_generator.rb', line 33 def self.next_migration_number(path) Time.now.utc.strftime("%Y%m%d%H%M%S") end |
Instance Method Details
#copy_role_file ⇒ Object
24 25 26 27 |
# File 'lib/generators/rolify/role/role_generator.rb', line 24 def copy_role_file template "initializer.rb", "config/initializers/rolify.rb" migration_template "migration.rb", "db/migrate/rolify_create_#{role_cname.tableize}" end |
#generate_role ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/generators/rolify/role/role_generator.rb', line 15 def generate_role template "role.rb", "app/models/#{role_cname.downcase}.rb" inject_into_class(model_path, user_cname.camelize) do " include Rolify::Roles\n" + " #{'# ' if ![:dynamic_shortcuts]}extend Rolify::Dynamic\n" + " has_and_belongs_to_many :roles#{", :class_name => \"" + role_cname.camelize + "\"" if role_cname != "Role"}, :join_table => :#{user_cname.tableize + "_" + role_cname.tableize}\n" end end |
#model_path ⇒ Object
29 30 31 |
# File 'lib/generators/rolify/role/role_generator.rb', line 29 def model_path File.join("app", "models", "#{user_cname.underscore}.rb") end |