Class: DeviseTraceableGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/devise_traceable/devise_traceable_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/generators/devise_traceable/devise_traceable_generator.rb', line 17

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)


13
14
15
# File 'lib/generators/devise_traceable/devise_traceable_generator.rb', line 13

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

.source_rootObject



9
10
11
# File 'lib/generators/devise_traceable/devise_traceable_generator.rb', line 9

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

Instance Method Details

#create_migration_fileObject



44
45
46
# File 'lib/generators/devise_traceable/devise_traceable_generator.rb', line 44

def create_migration_file
  migration_template 'migration.rb', "db/migrate/devise_create_#{name.downcase}_tracings.rb"
end

#invoke_orm_modelObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/generators/devise_traceable/devise_traceable_generator.rb', line 28

def invoke_orm_model
  if model_exists?
    say "* Model already exists."
  elsif options[:orm].present?
    invoke "model", ["#{name}Tracing"], :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_traceable #{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_traceable #{name}`."
  end
end