Class: DeviseStalkableGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
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.timestamped_migrations
    Time.now.utc.strftime('%Y%m%d%H%M%S')
  else
    '%.3d' % (current_migration_number(dirname) + 1)
  end
end

.orm_has_migration?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/generators/devise_stalkable/devise_stalkable_generator.rb', line 14

def self.orm_has_migration?
  Rails::Generators.options[:rails][:orm] == :active_record
end

.source_rootObject



10
11
12
# File 'lib/generators/devise_stalkable/devise_stalkable_generator.rb', line 10

def self.source_root
  @_devise_source_root ||= File.expand_path('../templates', __FILE__)
end

Instance Method Details

#create_migration_fileObject



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_modelObject



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 options[:orm].present?
    invoke "model", ["#{name}Login", "#{name}:belongs_to"], :migration => false,
      :orm => options[:orm]

    unless model_exists?
      abort "Tried to invoke the model generator for '#{options[: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