Class: LieutenantGovernor::Routing::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/lieutenant_governor/routing/extractor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(routes) ⇒ Extractor

Returns a new instance of Extractor.



19
20
21
# File 'lib/lieutenant_governor/routing/extractor.rb', line 19

def initialize(routes)
  @routes = routes
end

Instance Attribute Details

#routesObject (readonly)

Returns the value of attribute routes.



9
10
11
# File 'lib/lieutenant_governor/routing/extractor.rb', line 9

def routes
  @routes
end

Class Method Details

.extract(routes) ⇒ Hash

Takes applications routes and converts to hash

Parameters:

  • (ActionDispatch::Routing::RouteSet)

Returns:

  • (Hash)

    table mapping names to paths



14
15
16
17
# File 'lib/lieutenant_governor/routing/extractor.rb', line 14

def self.extract(routes)
  instance = new(routes)
  instance.extract
end

Instance Method Details

#extractObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/lieutenant_governor/routing/extractor.rb', line 23

def extract
  table = {}
  # possible to get blank strings as keys here
  routes.reduce(table) do |memo, obj|
    name = get_name(obj)
    path = get_path(obj)
    table[name] = path if name.length > 0 && path.length > 0
  end

  table
end