Class: SequelData::Migrate::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/sequel_data/migrate/generator.rb

Constant Summary collapse

VERSION_FORMAT =
"%Y%m%d%H%M%S"

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Generator

Returns a new instance of Generator.



10
11
12
# File 'lib/sequel_data/migrate/generator.rb', line 10

def initialize(config)
  @config = config
end

Instance Method Details

#create_migration(name) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sequel_data/migrate/generator.rb', line 14

def create_migration(name)
  version = Time.now.utc.strftime(VERSION_FORMAT)
  file_name = "#{version}_#{name}.rb"
  klass_name = name.split("_").map(&:capitalize).join
  content = <<~CONTENT
    class #{klass_name} < SequelData::Migrate::Migration
      def up
      end

      def down
      end
    end
  CONTENT

  File.join(config.migration_path, file_name).tap do |full_path|
    FileUtils.mkdir_p(config.migration_path)
    File.write(full_path, content)
  end
end