Class: Kurin::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/kurin/formatter.rb

Overview

This class outputs Rails routes into a clean and organized format.

Author:

  • Joshua Kendall

Instance Method Summary collapse

Constructor Details

#initializeFormatter

Returns a new instance of Formatter.



5
6
7
8
# File 'lib/kurin/formatter.rb', line 5

def initialize
  @buffer = []
  lines
end

Instance Method Details

#header(routes) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/kurin/formatter.rb', line 19

def header(routes)
  controller, action, verb, name, path = widths(routes)
  @buffer << [
    'Controller'.ljust(controller),
    'Action'.ljust(action),
    'Verb'.ljust(verb),
    'Prefix'.ljust(name),
    'URI Pattern'.ljust(path)
  ].join(' ')
  lines
end

#no_routesObject



37
38
39
40
41
42
43
44
# File 'lib/kurin/formatter.rb', line 37

def no_routes
  @buffer << <<-MESSAGE.strip_heredoc
    You don't have any routes defined!
    Please add some routes in config/routes.rb.
    For more information about routes, see the
    Rails guide: http://guides.rubyonrails.org/routing.html.
    MESSAGE
end

#resultObject



10
11
12
13
# File 'lib/kurin/formatter.rb', line 10

def result
  lines
  @buffer.join("\n")
end

#section(routes) ⇒ Object



31
32
33
34
35
# File 'lib/kurin/formatter.rb', line 31

def section(routes)
  routes.each do |route|
    @buffer << make_route(route, widths(routes)).join(' ')
  end
end

#section_title(title) ⇒ Object



15
16
17
# File 'lib/kurin/formatter.rb', line 15

def section_title(title)
  @buffer << "\n#{title}:"
end