Class: DeviseAuditLog::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/devise_audit_log/install_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object

Implement the required interface for Rails::Generators::Migration.



13
14
15
16
17
18
19
20
# File 'lib/generators/devise_audit_log/install_generator.rb', line 13

def self.next_migration_number(dirname) #:nodoc:
  next_migration_number = current_migration_number(dirname) + 1
  if ::ActiveRecord::Base.timestamped_migrations
    [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
  else
    "%.3d" % next_migration_number
  end
end

Instance Method Details

#ar_optional_flagObject



44
45
46
47
48
# File 'lib/generators/devise_audit_log/install_generator.rb', line 44

def ar_optional_flag
  if rails5?
    ", optional: true"
  end
end

#copy_migrationObject



22
23
24
# File 'lib/generators/devise_audit_log/install_generator.rb', line 22

def copy_migration
  migration_template "authentication_event_log_migration.rb", "db/migrate/create_authentication_event_logs.rb", migration_version: migration_version
end

#generate_modelObject



26
27
28
# File 'lib/generators/devise_audit_log/install_generator.rb', line 26

def generate_model
  template "authentication_event_log_model.rb", "app/models/authentication_event_log.rb", model_base_class: model_base_class, ar_optional_flag: ar_optional_flag
end

#migration_versionObject



30
31
32
33
34
# File 'lib/generators/devise_audit_log/install_generator.rb', line 30

def migration_version
  if rails5?
    "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
  end
end

#model_base_classObject



40
41
42
# File 'lib/generators/devise_audit_log/install_generator.rb', line 40

def model_base_class
  rails5? ? "ApplicationRecord" : "ActiveRecord::Base"
end

#rails5?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/generators/devise_audit_log/install_generator.rb', line 36

def rails5?
  Rails::VERSION::MAJOR >= 5
end