Class: ActiveRecord::ModelInheritance::Generators::ViewGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/active_record/model_inheritance/view/view_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dir) ⇒ Object



45
46
47
# File 'lib/generators/active_record/model_inheritance/view/view_generator.rb', line 45

def self.next_migration_number dir
  ::ActiveRecord::Generators::Base.next_migration_number dir
end

Instance Method Details

#create_migration_fileObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/generators/active_record/model_inheritance/view/view_generator.rb', line 29

def create_migration_file
  return if skip_generate_migration?

  if creating?
    migration_template(
      'create_migration.erb',
      ModelInheritance.migrations_path.join("create_#{table_name}.rb")
    )
  else
    migration_template(
      'update_migration.erb',
      ModelInheritance.migrations_path.join("update_#{table_name}_to_version_#{formatted_next_version}.rb")
    )
  end
end

#create_view_fileObject



22
23
24
25
26
27
# File 'lib/generators/active_record/model_inheritance/view/view_generator.rb', line 22

def create_view_file
  create_file ModelInheritance
                .views_path
                .join("#{table_name}_v#{formatted_next_version}.sql"),
              view_definition.to_sql
end