Class: PryRails::ShowMiddleware
- Inherits:
-
Pry::ClassCommand
- Object
- Pry::ClassCommand
- PryRails::ShowMiddleware
- Defined in:
- lib/pry-rails/commands/show_middleware.rb
Instance Method Summary collapse
Instance Method Details
#options(opt) ⇒ Object
15 16 17 |
# File 'lib/pry-rails/commands/show_middleware.rb', line 15 def (opt) opt.on :G, "grep", "Filter output by regular expression", :argument => true end |
#print_middleware(middlewares) ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/pry-rails/commands/show_middleware.rb', line 59 def print_middleware(middlewares) middlewares.each do |middleware| string = if middleware == Rails.application.class.to_s "run #{middleware}.routes" else "use #{middleware}" end output.puts string end end |
#process ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pry-rails/commands/show_middleware.rb', line 19 def process # Assumes there is only one Rack::Server instance. # TODO: Figure out what replaced Rack::Server so that we can show the # entire middleware stack on recent Rails versions. server = nil if defined?(Rack::Server) ObjectSpace.each_object(Rack::Server) do |object| server = object end end middlewares = [] if server stack = server.instance_variable_get("@wrapped_app") middlewares << stack.class.to_s while stack.instance_variable_defined?("@app") do stack = stack.instance_variable_get("@app") # Rails 3.0 uses the Application class rather than the application # instance itself, so we grab the instance. stack = Rails.application if stack == Rails.application.class middlewares << stack.class.to_s if stack != Rails.application end else middleware_names = Rails.application.middleware.map do |middleware| # After Rails 3.0, the middleware are wrapped in a special class # that responds to #name. if middleware.respond_to?(:name) middleware.name else middleware.inspect end end middlewares.concat middleware_names end middlewares << Rails.application.class.to_s print_middleware middlewares.grep(Regexp.new(opts[:G] || ".")) end |