Class: DeviseAuditLog::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- DeviseAuditLog::Generators::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/devise_audit_log/install_generator.rb
Class Method Summary collapse
-
.next_migration_number(dirname) ⇒ Object
Implement the required interface for Rails::Generators::Migration.
Instance Method Summary collapse
- #ar_optional_flag ⇒ Object
- #copy_migration ⇒ Object
- #generate_model ⇒ Object
- #migration_version ⇒ Object
- #model_base_class ⇒ Object
- #rails5? ⇒ Boolean
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. [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_flag ⇒ Object
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_migration ⇒ Object
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_model ⇒ Object
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_version ⇒ Object
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_class ⇒ Object
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
36 37 38 |
# File 'lib/generators/devise_audit_log/install_generator.rb', line 36 def rails5? Rails::VERSION::MAJOR >= 5 end |