Class: ScaffoldPlus::Generators::AncestryGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- ScaffoldPlus::Generators::AncestryGenerator
- Defined in:
- lib/generators/scaffold_plus/ancestry/ancestry_generator.rb
Instance Method Summary collapse
Instance Method Details
#add_migration ⇒ Object
23 24 25 26 |
# File 'lib/generators/scaffold_plus/ancestry/ancestry_generator.rb', line 23 def add_migration return unless .migration? migration_template "ancestry_migration.rb", "db/migrate/#{migration_name}.rb" end |
#update_controller ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/generators/scaffold_plus/ancestry/ancestry_generator.rb', line 39 def update_controller return unless .permit? text = ":ancestry" file = "app/controllers/#{table_name}_controller.rb" gsub_file file, /(permit\(.*)\)/, "\\1, #{text})" # Special case: no previous permit gsub_file file, /^(\s*params)\[:#{name}\]$/, "\\1.require(:#{name}).permit(#{text})" end |
#update_model ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/generators/scaffold_plus/ancestry/ancestry_generator.rb', line 28 def update_model inject_into_class "app/models/#{name}.rb", class_name do text = .before? ? "\n" : "" text << " has_ancestry" text << ", cache_depth: true" if .depth? text << "\n" text << "\n" if .after? text end end |