Class: MigrationWriter

Inherits:
Object
  • Object
show all
Defined in:
app/writers/migration_writer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_table) ⇒ MigrationWriter

Returns a new instance of MigrationWriter.



4
5
6
# File 'app/writers/migration_writer.rb', line 4

def initialize(data_table)
  @data_table = data_table
end

Instance Attribute Details

#data_tableObject (readonly)

Returns the value of attribute data_table.



2
3
4
# File 'app/writers/migration_writer.rb', line 2

def data_table
  @data_table
end

Class Method Details

.write_schema_migrationObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/writers/migration_writer.rb', line 8

def self.write_schema_migration
  FileUtils.mkdir_p('db/migrate')
  return if schema_migration_created?
  File.open(schema_migration, 'w') do |f|
    f.puts "class CreateGatherableSchema < ActiveRecord::Migration\ndef up\n  create_schema '\#{Gatherable.config.schema_name}'\nend\n\ndef down\n  drop_schema '\#{Gatherable.config.schema_name}'\nend\nend\n    schema_migration\n  end\n  puts \"created \#{schema_migration}\" if File.exists?(schema_migration)\nend\n"

Instance Method Details

#writeObject



27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/writers/migration_writer.rb', line 27

def write
  if matching_migrations.present?
    puts already_found_message
    return
  end
  FileUtils.mkdir_p('db/migrate')
  filename = "db/migrate/#{self.class.unique_timestamp}_#{file_suffix}"
  File.open(filename, 'w') do |f|
    f.puts file_template
  end
  puts "created #{filename}" if File.exists?(filename)
end