class OrientdbSchemaMigrator::MigrationGenerator

Attributes

name[R]

Public Class Methods

create_folder_if_not_exists!(path) click to toggle source
# File lib/orientdb_schema_migrator/migration_generator.rb, line 26
def self.create_folder_if_not_exists!(path)
  return if File.directory?(path)
  Dir.mkdir(path)
end
generate(name, path) click to toggle source
# File lib/orientdb_schema_migrator/migration_generator.rb, line 20
def self.generate(name, path)
  create_folder_if_not_exists!(path)
  mg = new(name, path)
  mg.write_file
end
new(name, path) click to toggle source
# File lib/orientdb_schema_migrator/migration_generator.rb, line 31
def initialize(name, path)
  @name = name
  validate_name!
  time = Time.now.strftime("%Y%m%d%H%M%S")
  file_name = @name.underscore
  @file_path = path + "/" + time + "_" + file_name + ".rb"
end

Public Instance Methods

write_file() click to toggle source
# File lib/orientdb_schema_migrator/migration_generator.rb, line 39
def write_file
  template_path = File.expand_path("../templates/migration_template.rb", __FILE__)
  File.open(@file_path, "w", 0644) do |f|
    f.write ERB.new(File.read(template_path)).result(MigrationGeneratorBinding.new(name).get_binding)
  end
end

Private Instance Methods

validate_name!() click to toggle source
# File lib/orientdb_schema_migrator/migration_generator.rb, line 50
def validate_name!
  if name.underscore.camelcase != name
    fail InvalidMigrationName.new("Name must be convertible between CamelCase and snake_case: #{name}")
  end
  if name.match(/[^a-zA-Z]+/)
    fail InvalidMigrationName.new("Name must consist only of alphabetic characters: #{name}")
  end
end