Class: OrientdbSchemaMigrator::MigrationGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/orientdb_schema_migrator/migration_generator.rb

Defined Under Namespace

Classes: MigrationGeneratorBinding

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path) ⇒ MigrationGenerator

Returns a new instance of MigrationGenerator.



31
32
33
34
35
36
37
# 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

Class Method Details

.create_folder_if_not_exists!(path) ⇒ Object



26
27
28
29
# 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) ⇒ Object



20
21
22
23
24
# 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

Instance Method Details

#write_fileObject



39
40
41
42
43
44
# 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