Class: AttributeStats::MigrationTemplateContents

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

Instance Method Summary collapse

Constructor Details

#initialize(table_info: [], migration_class_suffix: nil) ⇒ MigrationTemplateContents

Returns a new instance of MigrationTemplateContents.



3
4
5
6
7
8
9
# File 'lib/migration_generator/migration_template_contents.rb', line 3

def initialize(table_info: [], migration_class_suffix: nil)
  @table_info, @migration_class_suffix = table_info, migration_class_suffix
  @migration_buffer = ''
  @table_info.each do |table_info|
    add_migrations_for_table_to_buffer(table_info)
  end
end

Instance Method Details

#contentObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/migration_generator/migration_template_contents.rb', line 11

def content
  return nil if @migration_buffer.blank?
  output = "class RemoveUnusedAttributes#{@migration_class_suffix} < ActiveRecord::Migration"
  output << "[#{Rails::VERSION::STRING}]" if Rails::VERSION::MAJOR >= 5
  output << "\n#{warning_to_width}"
  output << "  def change\n\#{@migration_buffer}\n  end\nend\n  OUTPUT\n  output\nend\n"