class Navigable::Router::Printer
Constants
- VERBS
Attributes
dynamic[R]
memo[R]
static[R]
stdout[R]
Public Class Methods
new(static, dynamic, stdout = STDOUT)
click to toggle source
# File lib/navigable/router/printer.rb, line 10 def initialize(static, dynamic, stdout = STDOUT) @static, @dynamic = static, dynamic @stdout = stdout @memo = [] end
Public Instance Methods
print()
click to toggle source
# File lib/navigable/router/printer.rb, line 16 def print gather_static_routes gather_dynamic_routes print_routes end
Private Instance Methods
gather_dynamic_routes()
click to toggle source
# File lib/navigable/router/printer.rb, line 32 def gather_dynamic_routes dynamic.each do |verb, trie| trie.print(verb, memo) end end
gather_static_routes()
click to toggle source
# File lib/navigable/router/printer.rb, line 24 def gather_static_routes static.each do |verb, routes| routes.each do |path, endpoint| memo << { verb: verb, path: path, endpoint: endpoint } end end end
pad(str, length)
click to toggle source
# File lib/navigable/router/printer.rb, line 50 def pad(str, length) "%#{length}s" % str end
print_route(route)
click to toggle source
# File lib/navigable/router/printer.rb, line 46 def print_route(route) stdout.puts "#{pad(route[:verb], 8)} #{pad(route[:path], -50)} => #{route[:endpoint]}" end
print_routes()
click to toggle source
# File lib/navigable/router/printer.rb, line 38 def print_routes sorted_routes.each { |route| print_route(route) } end
sorted_routes()
click to toggle source
# File lib/navigable/router/printer.rb, line 42 def sorted_routes memo.sort_by { |route| "#{route[:path]}-#{VERBS.find_index(route[:verb])}" } end