Class: RailsMarkup::Generators::UninstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- RailsMarkup::Generators::UninstallGenerator
- Defined in:
- lib/generators/rails_markup/uninstall_generator.rb
Instance Method Summary collapse
- #remove_auth_controller ⇒ Object
- #remove_bin_wrapper ⇒ Object
- #remove_initializer ⇒ Object
- #remove_mcp_config ⇒ Object
- #remove_migration ⇒ Object
- #remove_route_mount ⇒ Object
- #remove_toolbar_from_layouts ⇒ Object
- #show_post_uninstall ⇒ Object
Instance Method Details
#remove_auth_controller ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/generators/rails_markup/uninstall_generator.rb', line 26 def remove_auth_controller path = "app/controllers/rails_markup_auth_controller.rb" full_path = File.join(destination_root, path) return unless File.exist?(full_path) content = File.read(full_path) if content.include?("RailsMarkupAuthController") remove_file path else say_status :skip, "#{path} doesn't match generated pattern — leaving in place", :yellow end end |
#remove_bin_wrapper ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/generators/rails_markup/uninstall_generator.rb', line 71 def remove_bin_wrapper path = "bin/markup" full_path = File.join(destination_root, path) return unless File.exist?(full_path) content = File.read(full_path) if content.include?("rails_markup") || content.include?("RailsMarkup") remove_file path else say_status :skip, "#{path} doesn't reference rails_markup — leaving in place", :yellow end end |
#remove_initializer ⇒ Object
21 22 23 24 |
# File 'lib/generators/rails_markup/uninstall_generator.rb', line 21 def remove_initializer path = "config/initializers/rails_markup.rb" remove_file path if File.exist?(File.join(destination_root, path)) end |
#remove_mcp_config ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/generators/rails_markup/uninstall_generator.rb', line 51 def remove_mcp_config mcp_path = File.join(destination_root, ".mcp.json") return unless File.exist?(mcp_path) config = JSON.parse(File.read(mcp_path)) server = config.dig("mcpServers", "rails-markup") return unless server config["mcpServers"].delete("rails-markup") if config["mcpServers"].empty? remove_file ".mcp.json" else File.write(mcp_path, JSON.pretty_generate(config) + "\n") say_status :remove, "rails-markup entry from .mcp.json", :green end rescue JSON::ParserError say_status :skip, ".mcp.json has invalid JSON — leaving in place", :yellow end |
#remove_migration ⇒ Object
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/generators/rails_markup/uninstall_generator.rb', line 84 def remove_migration return unless [:remove_migration] migration = Dir.glob(File.join(destination_root, "db/migrate/*_create_rails_markup_annotations.rb")).first if migration remove_file migration.sub("#{destination_root}/", "") else say_status :skip, "no rails_markup migration found", :yellow end end |
#remove_route_mount ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/generators/rails_markup/uninstall_generator.rb', line 13 def remove_route_mount route_file = File.join(destination_root, "config/routes.rb") return unless File.exist?(route_file) gsub_file "config/routes.rb", /^\s*mount RailsMarkup::Engine.*\n/, "" say_status :remove, "RailsMarkup engine mount from routes", :green end |
#remove_toolbar_from_layouts ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/rails_markup/uninstall_generator.rb', line 39 def Dir.glob(File.join(destination_root, "app/views/layouts/*.html.erb")).each do |layout| relative = layout.sub("#{destination_root}/", "") content = File.read(layout) next unless content.include?("rails_markup/shared/toolbar") gsub_file relative, /^\s*<%# Rails Markup annotation toolbar %>\n/, "" gsub_file relative, /^\s*<% if lookup_context\.exists\?\("rails_markup\/shared\/toolbar".*%>\n\s*<%= render "rails_markup\/shared\/toolbar" %>\n\s*<% end %>\n/, "" say_status :remove, "toolbar from #{relative}", :green end end |
#show_post_uninstall ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/generators/rails_markup/uninstall_generator.rb', line 95 def show_post_uninstall say "" say "Rails Markup uninstalled.", :green say "" say "Remaining manual steps:" say " 1. Remove 'rails_markup' from your Gemfile and run bundle" unless [:remove_migration] say " 2. Drop the table: rails db:migrate:down VERSION=<migration_version>" say " Or: rails generate rails_markup:uninstall --remove-migration" end say " 3. Search for stale references: grep -r 'rails_markup\\|RailsMarkup' app/ config/" say "" end |