Class: Michel::Generators::ViewGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Michel::Generators::ViewGenerator
- Includes:
- Scenic
- Defined in:
- lib/generators/michel/view/view_generator.rb
Instance Method Summary collapse
- #add_associations_to_models ⇒ Object
- #create_index_in_migration ⇒ Object
- #create_scenic_model ⇒ Object
- #create_sql_file ⇒ Object
Instance Method Details
#add_associations_to_models ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/michel/view/view_generator.rb', line 37 def add_associations_to_models has_many_associations = template_content("has_many_associations.erb") inject_into_class "app/models/#{Michel.availability_class_underscore}.rb", Michel.availability_class_name, has_many_associations inject_into_class "app/models/#{Michel.resource_class_underscore}.rb", Michel.resource_class_name, has_many_associations belongs_to_associations = template_content("belongs_to_associations.erb") case behavior when :invoke inject_into_class "app/models/available_time_slot.rb", "AvailableTimeSlot", belongs_to_associations end end |
#create_index_in_migration ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/generators/michel/view/view_generator.rb', line 9 def create_index_in_migration self.destination_root = Rails.root puts "Generating #{Michel.booking_class_table_name} index migration" invoke "migration", ["add_index_to_#{Michel.booking_class_table_name}"] index_migration_content = template_content("index_migration.erb") Dir.glob(Rails.root.join("db/migrate/*add_index_to_#{Michel.booking_class_table_name}.rb")).each do |file| inject_into_file file, index_migration_content, after: "def change" end end |
#create_scenic_model ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/generators/michel/view/view_generator.rb', line 20 def create_scenic_model self.destination_root = Rails.root puts "Creating scenic model available_time_slot" invoke "scenic:model", ["available_time_slots"], {"materialized" => true, "test_framework" => false} Dir.glob(Rails.root.join("db/migrate/*create_available_time_slots.rb")).each do |file| gsub_file file, /change/, "up" inject_into_class file, "CreateAvailableTimeSlots", template_content("view_migration.rb") end end |
#create_sql_file ⇒ Object
32 33 34 35 |
# File 'lib/generators/michel/view/view_generator.rb', line 32 def create_sql_file puts "Creating materialized view SQL at db/views/available_time_slots_v01.sql" template "view.erb", "db/views/available_time_slots_v01.sql", {force: true} end |