Class: Incline::Helpers::RouteHashFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/incline/helpers/route_hash_formatter.rb

Overview

A “formatter” that simply collects formatted route data.

Instance Method Summary collapse

Constructor Details

#initializeRouteHashFormatter

Creates a new hash formatter for the route inspector.



8
9
10
11
# File 'lib/incline/helpers/route_hash_formatter.rb', line 8

def initialize
  @buffer = []
  @engine = ''
end

Instance Method Details

#header(routes) ⇒ Object

Does nothing for this formatter.



27
28
29
# File 'lib/incline/helpers/route_hash_formatter.rb', line 27

def header(routes)
  # no need for a header
end

#no_routesObject

Does nothing for this formatter.



33
34
35
# File 'lib/incline/helpers/route_hash_formatter.rb', line 33

def no_routes
  # no need to do anything here either.
end

#resultObject

Gets the resulting hash from the route inspector.



15
16
17
# File 'lib/incline/helpers/route_hash_formatter.rb', line 15

def result
  @buffer
end

#section(routes) ⇒ Object

Adds the specified routes to the resulting hash.



39
40
41
42
43
# File 'lib/incline/helpers/route_hash_formatter.rb', line 39

def section(routes)
  routes.each do |r|
    @buffer << r.symbolize_keys.merge(engine: @engine)
  end
end

#section_title(title) ⇒ Object

Analyzes the section title to get the current engine name.



21
22
23
# File 'lib/incline/helpers/route_hash_formatter.rb', line 21

def section_title(title)
  @engine = title.include?(' ') ? title.rpartition(' ')[2] : title
end