Class: Textacular::MigrationGenerator

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

Instance Method Summary collapse

Constructor Details

#initialize(filename, content) ⇒ MigrationGenerator

Returns a new instance of MigrationGenerator.



4
5
6
7
8
# File 'lib/textacular/migration_generator.rb', line 4

def initialize(filename, content)
  @filename = filename
  @content = content
  @output_stream = nil
end

Instance Method Details

#generate_migrationObject



10
11
12
13
14
# File 'lib/textacular/migration_generator.rb', line 10

def generate_migration
  stream_output do |io|
    io.puts(@content)
  end
end

#stream_output(now = Time.now.utc, &block) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/textacular/migration_generator.rb', line 16

def stream_output(now = Time.now.utc, &block)
  if !@output_stream && defined?(Rails)
    FileUtils.mkdir_p(File.dirname(migration_file_name(now)))
    File.open(migration_file_name(now), 'w', &block)
  else
    @output_stream ||= $stdout

    yield @output_stream
  end
end