class PryRailsDiffRoutes::DiffRoutes
Constants
- A_MODE
- M_MODE
- N_MODE
- R_MODE
Attributes
_previous_routes[RW]
Public Instance Methods
options(opt)
click to toggle source
# File lib/pry_rails_diff_routes/commands/diff_routes.rb, line 30 def options(opt) opt.on :S, "save", "Save current routes", as: String opt.on :R, "removed", "Show removed routes", as: String opt.on :M, "modified", "Show modified routes", as: String opt.on :N, "new", "Show new routes", as: String end
process()
click to toggle source
# File lib/pry_rails_diff_routes/commands/diff_routes.rb, line 41 def process Rails.application.reload_routes! all_routes = Rails.application.routes.routes return save_routes(all_routes) if opts[:S] removed_mode = opts[:R] ? R_MODE : 0 modified_mode = opts[:M] ? M_MODE : 0 new_mode = opts[:N] ? N_MODE : 0 display_mode = removed_mode | modified_mode | new_mode output.puts process_diff(all_routes, display_mode) end
process_diff(current_routes, mode)
click to toggle source
# File lib/pry_rails_diff_routes/commands/diff_routes.rb, line 74 def process_diff(current_routes, mode) routes = RoutesDiffProcessor.new( DiffRoutes._previous_routes, wrap_routes(current_routes), mode ) if routes.changed? routes else "No routes changed." end end
save_routes(routes)
click to toggle source
`opts`.
# File lib/pry_rails_diff_routes/commands/diff_routes.rb, line 56 def save_routes(routes) DiffRoutes._previous_routes = wrap_routes(routes) nil end
wrap_routes(routes)
click to toggle source
# File lib/pry_rails_diff_routes/commands/diff_routes.rb, line 61 def wrap_routes(routes) prev_name = nil routes.reject(&:internal).map do |route| if route.name.nil? route.instance_variable_set(:@name, prev_name) else prev_name = route.name end RouteWrapper.new(route) end end