Class: Mongration::CreateMigration::MigrationFileWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/mongration/create_migration/migration_file_writer.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name, options = {}) ⇒ MigrationFileWriter

Returns a new instance of MigrationFileWriter.



11
12
13
14
15
# File 'lib/mongration/create_migration/migration_file_writer.rb', line 11

def initialize(file_name, options = {})
  @file_name = file_name
  @up = options[:up]
  @down = options[:down]
end

Class Method Details

.write(file_name, options = {}) ⇒ Object



7
8
9
# File 'lib/mongration/create_migration/migration_file_writer.rb', line 7

def self.write(file_name, options = {})
  new(file_name, options).write
end

Instance Method Details

#writeObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mongration/create_migration/migration_file_writer.rb', line 17

def write
  path = ::File.join(Mongration.configuration.dir, @file_name)
  ::File.open(path, 'w') do |file|
    file.write("class \#{class_name}\n  def self.up\n    \#{@up}\n  end\n\n  def self.down\n    \#{@down}\n  end\nend\n"
    )
  end
  path
end