Class: Pigeon::Generators::Hanami::MigrationGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/pigeon/generators/hanami/migration_generator.rb

Overview

Generator for creating the outbox message table migration for Hanami applications

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_name = nil) ⇒ MigrationGenerator

Returns a new instance of MigrationGenerator.



12
13
14
# File 'lib/pigeon/generators/hanami/migration_generator.rb', line 12

def initialize(app_name = nil)
  @app_name = app_name || detect_app_name
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



10
11
12
# File 'lib/pigeon/generators/hanami/migration_generator.rb', line 10

def app_name
  @app_name
end

Instance Method Details

#generateString

Generate the migration file

Returns:

  • (String)

    Path to the generated file



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pigeon/generators/hanami/migration_generator.rb', line 18

def generate
  timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
  filename = "db/migrations/#{timestamp}_create_outbox_messages.rb"

  # Create the migrations directory if it doesn't exist
  FileUtils.mkdir_p("db/migrations")

  # Write the migration file
  File.write(filename, migration_content)

  filename
end