Class: Commento::Generators::ActiveRecordGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Commento::Generators::ActiveRecordGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/commento/active_record_generator.rb
Instance Attribute Summary collapse
-
#columns_change_data ⇒ Object
readonly
Returns the value of attribute columns_change_data.
-
#tables_change_data ⇒ Object
readonly
Returns the value of attribute tables_change_data.
Class Method Summary collapse
- .migration_version ⇒ Object
- .next_migration_number(dirname) ⇒ Object
- .requires_migration_number? ⇒ Boolean
Instance Method Summary collapse
Instance Attribute Details
#columns_change_data ⇒ Object (readonly)
Returns the value of attribute columns_change_data.
14 15 16 |
# File 'lib/generators/commento/active_record_generator.rb', line 14 def columns_change_data @columns_change_data end |
#tables_change_data ⇒ Object (readonly)
Returns the value of attribute tables_change_data.
14 15 16 |
# File 'lib/generators/commento/active_record_generator.rb', line 14 def tables_change_data @tables_change_data end |
Class Method Details
.migration_version ⇒ Object
20 21 22 |
# File 'lib/generators/commento/active_record_generator.rb', line 20 def self.migration_version "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" if requires_migration_number? end |
.next_migration_number(dirname) ⇒ Object
16 17 18 |
# File 'lib/generators/commento/active_record_generator.rb', line 16 def self.next_migration_number(dirname) ::ActiveRecord::Generators::Base.next_migration_number(dirname) end |
.requires_migration_number? ⇒ Boolean
24 25 26 |
# File 'lib/generators/commento/active_record_generator.rb', line 24 def self.requires_migration_number? Rails::VERSION::MAJOR.to_i >= 5 end |
Instance Method Details
#create_migration_file ⇒ Object
28 29 30 31 32 |
# File 'lib/generators/commento/active_record_generator.rb', line 28 def create_migration_file generate_migration_data migration_template 'migration.erb', 'db/migrate/commento_add_comments_to_tables_and_columns.rb' end |
#generate_migration_data ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/generators/commento/active_record_generator.rb', line 38 def generate_migration_data @tables_without_comment = [] @table_report = {} check_comments_for_database(Commento.adapter.fetch_comments_for_database) @tables_change_data = @tables_without_comment .map { |table_name| "change_table_comment(:#{table_name}, from: nil, to: '')" } .join("\n ") @columns_change_data = @table_report.map do |table_name, column_names| column_names.map do |column_name| "change_column_comment(:#{table_name}, :#{column_name}, from: nil, to: '')" end end.flatten.join("\n ") end |
#migration_version ⇒ Object
34 35 36 |
# File 'lib/generators/commento/active_record_generator.rb', line 34 def migration_version self.class.migration_version end |