Class: Log::Analyzer::Routes

Inherits:
ActionDispatch::Journey::Routes
  • Object
show all
Defined in:
lib/log-analyzer/routes.rb

Instance Method Summary collapse

Constructor Details

#initialize(routes_text) ⇒ Routes

Returns a new instance of Routes.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/log-analyzer/routes.rb', line 6

def initialize(routes_text)
  super()
  routes_text.scan(regexp) do |request_method, request_path, requirements, constraints|
    constraints = if constraints.nil? || constraints.empty?
                    []
                  else
                    eval(constraints)
                  end.map do |constraint|
                    constraint.is_a?(String) ? eval(constraint) : constraint
                  end
    app = ActionDispatch::Routing::Mapper::Constraints.new(nil, constraints, true)

    path_pattern = Pattern.from_string(request_method, request_path, requirements)
    add_route(app, path_pattern, {request_method: /^#{request_method}$/}, {}, {})
  end
end