class RoutesCoverage::Formatters::FullText::RouteFormatter
Constants
- HEADER
Attributes
buffer[R]
Public Class Methods
new(result=nil, _settings=nil, output_hits=false)
click to toggle source
# File lib/routes_coverage/formatters/full_text.rb, line 8 def initialize result=nil, _settings=nil, output_hits=false @buffer = [] @result = result @output_hits = output_hits @output_prefix = false end
Public Instance Methods
header(routes)
click to toggle source
# File lib/routes_coverage/formatters/full_text.rb, line 27 def header(routes) @buffer << draw_header(routes) end
no_routes(_routes_from_rails5=nil)
click to toggle source
# File lib/routes_coverage/formatters/full_text.rb, line 31 def no_routes _routes_from_rails5=nil @buffer << "\tNone" end
result()
click to toggle source
# File lib/routes_coverage/formatters/full_text.rb, line 15 def result @buffer.join("\n") end
section(routes)
click to toggle source
# File lib/routes_coverage/formatters/full_text.rb, line 23 def section(routes) @buffer << draw_section(routes) end
section_title(title)
click to toggle source
# File lib/routes_coverage/formatters/full_text.rb, line 19 def section_title(title) @buffer << "\n#{title}:" end
Private Instance Methods
draw_header(routes)
click to toggle source
# File lib/routes_coverage/formatters/full_text.rb, line 57 def draw_header(routes) name_width, verb_width, path_width, reqs_width = widths(routes) "#{"Prefix".rjust(name_width) if @output_prefix} #{"Verb".ljust(verb_width)} #{"URI Pattern".ljust(path_width)} #{"Controller#Action".ljust(reqs_width)}#{' Hits' if @output_hits}" end
draw_section(routes)
click to toggle source
# File lib/routes_coverage/formatters/full_text.rb, line 37 def draw_section(routes) header_lengths = HEADER.map(&:length) name_width, verb_width, path_width, reqs_width = widths(routes).zip(header_lengths).map(&:max) hits = nil routes.map do |r| # puts "route is #{r.inspect}" if @output_hits # hits = " ?" if r[:original].respond_to?(:__getobj__) original_route = r[:original].__getobj__ # SimpleDelegator else original_route = r[:original] end hits = " #{@result.route_hit_counts[original_route]}" end "#{r[:name].rjust(name_width) if @output_prefix} #{r[:verb].ljust(verb_width)} #{r[:path].ljust(path_width)} #{r[:reqs].ljust(reqs_width)}#{hits}" end end
widths(routes)
click to toggle source
# File lib/routes_coverage/formatters/full_text.rb, line 63 def widths(routes) [routes.map { |r| r[:name].length }.max || 0, routes.map { |r| r[:verb].length }.max || 0, routes.map { |r| r[:path].length }.max || 0, routes.map { |r| r[:reqs].length }.max || 0, ] end