Class: ROM::Cassandra::Migrations::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/cassandra/migrations/generator.rb

Overview

Generates the migration with given name at the target folder

Examples:

ROM::Cassandra::Migrations::Generator.call "create_users", "/db/migrate"
# => "/db/migrate/20150827133303_create_users.rb"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path) ⇒ Generator

Initializes the generator with path to target folder and migration name

Parameters:

  • path (String)
  • name (String)


30
31
32
33
34
35
# File 'lib/rom/cassandra/migrations/generator.rb', line 30

def initialize(name, path)
  @path    = path
  @name    = Inflecto.underscore(name)
  @klass   = Inflecto.camelize(name)
  @version = Time.new.strftime "%Y%m%d%H%M%S"
end

Class Method Details

.call(name, path) ⇒ String

Initializes and calls the generator at once

Parameters:

  • path (String)
  • name (String)

Returns:

  • (String)

    the full path to the migration



21
22
23
# File 'lib/rom/cassandra/migrations/generator.rb', line 21

def self.call(name, path)
  new(name, path).call
end

Instance Method Details

#callString

Generates the migration

Returns:

  • (String)

    the full path to the migration



41
42
43
44
45
46
# File 'lib/rom/cassandra/migrations/generator.rb', line 41

def call
  FileUtils.mkdir_p path
  File.write target, content

  target
end