Class: AttributeStats::GenerateMigration
- Inherits:
-
Object
- Object
- AttributeStats::GenerateMigration
- Defined in:
- lib/stats_generation/generate_migration.rb
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(table_info: [], options: {}) ⇒ GenerateMigration
constructor
A new instance of GenerateMigration.
- #to_json ⇒ Object
- #to_migration_file ⇒ Object
Constructor Details
#initialize(table_info: [], options: {}) ⇒ GenerateMigration
Returns a new instance of GenerateMigration.
4 5 6 7 8 9 10 11 |
# File 'lib/stats_generation/generate_migration.rb', line 4 def initialize(table_info: [], options: {}) @table_info, @options = table_info, @up_buffer = [] @down_buffer = [] @table_info.each do |table_info| add_migrations_for_table_to_buffer(table_info) end end |
Instance Method Details
#data ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/stats_generation/generate_migration.rb', line 13 def data { up_commands: @up_buffer, down_commands: @down_buffer, warning: warning } end |
#to_json ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/stats_generation/generate_migration.rb', line 38 def to_json { up_commands: @up_buffer, down_commands: @down_buffer, warning: warning } end |
#to_migration_file ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/stats_generation/generate_migration.rb', line 21 def to_migration_file output = "class RemoveUnusedAttributes < ActiveRecord::Migration" output << "[#{Rails::VERSION::STRING}]" if Rails::VERSION::MAJOR >= 5 output << "\n#{warning_to_width}" output << <<-OUTPUT def up # #{@up_buffer.join("\n # ")} end def down # #{@down_buffer.join("\n # ")} end end OUTPUT output end |