Class: DeviseStalkableGenerator
- Inherits:
-
Rails::Generators::NamedBase
- Object
- Rails::Generators::NamedBase
- DeviseStalkableGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/devise_stalkable/devise_stalkable_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.next_migration_number(dirname) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/generators/devise_stalkable/devise_stalkable_generator.rb', line 18 def self.next_migration_number(dirname) if ActiveRecord::Base. Time.now.utc.strftime('%Y%m%d%H%M%S') else '%.3d' % (current_migration_number(dirname) + 1) end end |
.orm_has_migration? ⇒ Boolean
14 15 16 |
# File 'lib/generators/devise_stalkable/devise_stalkable_generator.rb', line 14 def self.orm_has_migration? Rails::Generators.[:rails][:orm] == :active_record end |
.source_root ⇒ Object
10 11 12 |
# File 'lib/generators/devise_stalkable/devise_stalkable_generator.rb', line 10 def self.source_root @_devise_source_root ||= File.('../templates', __FILE__) end |
Instance Method Details
#create_migration_file ⇒ Object
46 47 48 |
# File 'lib/generators/devise_stalkable/devise_stalkable_generator.rb', line 46 def create_migration_file migration_template 'migration.rb', "db/migrate/devise_create_#{name.downcase}_logins.rb" end |
#invoke_orm_model ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/generators/devise_stalkable/devise_stalkable_generator.rb', line 29 def invoke_orm_model if model_exists? say "* Model #{name}Login already exists." elsif [:orm].present? invoke "model", ["#{name}Login", "#{name}:belongs_to"], :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_stalkable #{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_stalkable #{name}`." end end |