class Rack::App::CLI::DefaultCommands::ShowRoutes
Constants
- FIELD_FETCHERS
- SORT_FIELDS
Private Instance Methods
fetch_field(endpoint, field)
click to toggle source
# File lib/rack/app/cli/default_commands/show_routes.rb, line 63 def fetch_field(endpoint, field) instance_exec(endpoint, &FIELD_FETCHERS[field]) end
format(endpoints)
click to toggle source
# File lib/rack/app/cli/default_commands/show_routes.rb, line 67 def format(endpoints) fields = get_fields widths = width_by(endpoints, fields) endpoints.map do |endpoint| outputs = [] outputs << fields.map do |field| fetch_field(endpoint, field).to_s.ljust(widths[field]) end.join(' ') if @middlewares outputs << pretty_print_middlewares(endpoint) end outputs.join("\n") end.join("\n") end
get_fields()
click to toggle source
# File lib/rack/app/cli/default_commands/show_routes.rb, line 26 def get_fields if @verbose return FIELD_FETCHERS.keys end fields = [:request_method, :request_path] fields << :description if @description fields << :source_location if @source_location fields end
pretty_print_middlewares(endpoint)
click to toggle source
# File lib/rack/app/cli/default_commands/show_routes.rb, line 98 def pretty_print_middlewares(endpoint) builder = FakeBuilder.new endpoint.config.middlewares.each do |builder_block| builder.instance_exec(builder, &builder_block) end builder.middlewares.map do |middleware| ["\t", '* ', middleware].join end.join("\n") end
sort(endpoints)
click to toggle source
# File lib/rack/app/cli/default_commands/show_routes.rb, line 46 def sort(endpoints) endpoints.sort_by { |endpoint| SORT_FIELDS.map { |sf| fetch_field(endpoint, sf) } } end
width_by(endpoints, fields)
click to toggle source
# File lib/rack/app/cli/default_commands/show_routes.rb, line 37 def width_by(endpoints, fields) fields.reduce({}) do |widths, property| widths[property] = endpoints.map { |endpoint| fetch_field(endpoint, property).to_s.length }.max widths end end