Class: SimpleDataMigrations::TemplateGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/simple_data_migrations/template_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_template_fileObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/generators/simple_data_migrations/template_generator.rb', line 7

def create_template_file
  version = Time.now.utc.strftime("%Y%m%d%H%M%S") # Rails db migration like
  path = SimpleDataMigrations::Utils.root.join("#{version}_#{file_name}.rb")

  create_file path do
<<-TEMPLATE
ApplicationRecord.transaction do
  # Your code

  SimpleDataMigrations::Entry.create!(version: #{version})
end
TEMPLATE
  end
end