class ScaffoldPlus::Generators::AncestryGenerator

Public Instance Methods

add_migration() click to toggle source
# File lib/generators/scaffold_plus/ancestry/ancestry_generator.rb, line 23
def add_migration
  return unless options.migration?
  migration_template "ancestry_migration.rb", "db/migrate/#{migration_name}.rb"
end
update_controller() click to toggle source
# File lib/generators/scaffold_plus/ancestry/ancestry_generator.rb, line 39
def update_controller
  return unless options.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() click to toggle source
# 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 = options.before? ? "\n" : ""
    text << "  has_ancestry"
    text << ", cache_depth: true" if options.depth?
    text << "\n"
    text << "\n" if options.after?
    text
  end
end

Protected Instance Methods

migration_name() click to toggle source
# File lib/generators/scaffold_plus/ancestry/ancestry_generator.rb, line 50
def migration_name
  "add_ancestry_to_#{table_name}"
end