Class: QueryableLogsGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/generators/queryable_logs_generator.rb', line 30

def self.next_migration_number(dirname)
  if ActiveRecord::Base.timestamped_migrations
    current_time = Time.now.utc
    current_time.strftime("%Y%m%d%H%M%S")
  else
    "%.3d" % (current_numeric_version(dirname) + 1)
  end
end

Instance Method Details

#copy_initializer_fileObject



12
13
14
# File 'lib/generators/queryable_logs_generator.rb', line 12

def copy_initializer_file
  copy_file "initializer.rb", "config/initializers/trail_log.rb"
end

#copy_migration_fileObject



8
9
10
# File 'lib/generators/queryable_logs_generator.rb', line 8

def copy_migration_file
  migration_template "migration.rb", "db/migrate/create_trail_logs.rb", migration_version: migration_version
end

#copy_task_fileObject



16
17
18
# File 'lib/generators/queryable_logs_generator.rb', line 16

def copy_task_file
  copy_file "task.rb", "lib/tasks/queryable_logs_parse_save.rake"
end

#migration_versionObject



24
25
26
27
28
# File 'lib/generators/queryable_logs_generator.rb', line 24

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

#rails5_and_up?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/generators/queryable_logs_generator.rb', line 20

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