class ROM::Cassandra::Migrations::Generator

Generates the migration with given name at the target folder

@example

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

Attributes

name[R]
path[R]
version[R]

Public Class Methods

call(name, path) click to toggle source

Initializes and calls the generator at once

@param (see initialize)

@return (see call)

# File lib/rom/cassandra/migrations/generator.rb, line 21
def self.call(name, path)
  new(name, path).call
end
new(name, path) click to toggle source

Initializes the generator with path to target folder and migration name

@param [String] path @param [String] name

# 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

Public Instance Methods

call() click to toggle source

Generates the migration

@return [String] the full path to the migration

# File lib/rom/cassandra/migrations/generator.rb, line 41
def call
  FileUtils.mkdir_p path
  File.write target, content

  target
end

Private Instance Methods

content() click to toggle source
# File lib/rom/cassandra/migrations/generator.rb, line 52
def content
  ERB.new(File.read source).result(binding)
end
source() click to toggle source
# File lib/rom/cassandra/migrations/generator.rb, line 56
def source
  File.expand_path("../generator/migration.erb", __FILE__)
end
target() click to toggle source
# File lib/rom/cassandra/migrations/generator.rb, line 60
def target
  File.join(path, "#{version}_#{name}.rb")
end