Class: RakeRoutesNormalizer::RouteSet

Inherits:
Valuable
  • Object
show all
Defined in:
lib/rake_routes_normalizer/route_set.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(text) ⇒ Object



5
6
7
8
9
# File 'lib/rake_routes_normalizer/route_set.rb', line 5

def self.parse(text)
  RouteSet.new.tap do |result|
    result.routes = text.split("\n").reject{|line| line =~ /^\s*$/}.map{|line| Route.parse(line)}
  end
end

Instance Method Details

#normalizeObject



11
12
13
14
15
16
17
18
19
# File 'lib/rake_routes_normalizer/route_set.rb', line 11

def normalize
  result = routes.inject(RouteSet.new) do|route_set, route|
    previous_route = route_set.routes.detect{|r| route.url_pattern == r.url_pattern }
    route_set.routes << route.normalize(:previous_route => previous_route)
    route_set
  end
  result.routes.sort!
  result
end