class StrongRoutes::Rails::RouteMapper

Attributes

route_set[R]

Public Class Methods

map(route_set) click to toggle source
# File lib/strong_routes/rails/route_mapper.rb, line 8
def self.map(route_set)
  route_mapper = self.new(route_set)
  route_mapper.map
end
new(route_set) click to toggle source
# File lib/strong_routes/rails/route_mapper.rb, line 13
def initialize(route_set)
  @route_set = route_set
end

Public Instance Methods

map() click to toggle source

Map the route set to a collection of the top level segments.

# File lib/strong_routes/rails/route_mapper.rb, line 18
def map
  map = matches.map { |match_data| match_data[:path] }
  map.compact!
  map.uniq!
  map
end

Private Instance Methods

matches() click to toggle source

Convert the path strings into match data objects, capturing all segments except optional ones (e.g. :format).

# File lib/strong_routes/rails/route_mapper.rb, line 29
def matches
  matches = paths.map { |path| path.match(/\A(?<path>[-:\w\/]+)\/*.*\Z/) }
  matches.compact!
  matches.uniq!
  matches
end
paths() click to toggle source

Extract the route paths from the route objects so we have a simple string to interact with.

# File lib/strong_routes/rails/route_mapper.rb, line 38
def paths
  paths = route_set.routes.map { |route| route.path.spec.to_s }
  paths.uniq!
  paths
end