Class: Devise::Generators::DeviseGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- Devise::Generators::DeviseGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/bobby/bobby/bobby_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_bobby_routes ⇒ Object
- #copy_migration_template ⇒ Object
- #inject_devise_config_into_model ⇒ Object
- #invoke_orm_model ⇒ Object
Class Method Details
.next_migration_number(path) ⇒ Object
18 19 20 |
# File 'lib/generators/bobby/bobby/bobby_generator.rb', line 18 def self.next_migration_number(path) Time.now.utc.strftime("%Y%m%d%H%M%S") end |
.orm_has_migration? ⇒ Boolean
14 15 16 |
# File 'lib/generators/bobby/bobby/bobby_generator.rb', line 14 def self.orm_has_migration? Rails::Generators.[:rails][:orm] == :active_record end |
Instance Method Details
#add_bobby_routes ⇒ Object
71 72 73 74 75 |
# File 'lib/generators/bobby/bobby/bobby_generator.rb', line 71 def add_bobby_routes route "ressources :roles" route "ressources :permissions" route "ressources :group_users" end |
#copy_migration_template ⇒ Object
66 67 68 69 |
# File 'lib/generators/bobby/bobby/bobby_generator.rb', line 66 def copy_migration_template return unless .migration? migration_template "migration.rb", "db/migrate/bobby_create_tables" end |
#inject_devise_config_into_model ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/generators/bobby/bobby/bobby_generator.rb', line 43 def inject_devise_config_into_model devise_class_setup = <<-CONTENT # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, :lockable and :timeoutable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable CONTENT case [:orm].to_s when "mongoid" inject_into_file model_path, devise_class_setup, :after => "include Mongoid::Document\n" when "data_mapper" inject_into_file model_path, devise_class_setup, :after => "include DataMapper::Resource\n" when "active_record" inject_into_class model_path, class_name, devise_class_setup + <<-CONTENT # Setup accessible (or protected) attributes for your model attr_accessible :email, :password, :password_confirmation CONTENT end end |
#invoke_orm_model ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/generators/bobby/bobby/bobby_generator.rb', line 25 def invoke_orm_model return unless behavior == :invoke if model_exists? say "* Model already exists. Adding Devise behavior." elsif [:orm].present? invoke "model", [name], :migration => false, :orm => [:orm] unless model_exists? abort "Tried to invoke the model generator for '#{[:orm]}' but could not find it.\n" << "Please create your model by hand before calling `rails g devise #{name}`." end else abort "Cannot create a devise model because config.generators.orm is blank.\n" << "Please create your model by hand or configure your generators orm before calling `rails g devise #{name}`." end end |