class Rough::Route

Attributes

route[R]

Public Class Methods

new(route) click to toggle source
# File lib/rough/route.rb, line 9
def initialize(route)
  @route = route
end

Public Instance Methods

path() click to toggle source
# File lib/rough/route.rb, line 13
def path
  @path ||= load_path
end
request_method() click to toggle source
# File lib/rough/route.rb, line 17
def request_method
  @request_method ||= load_request_method
end

Private Instance Methods

load_path() click to toggle source
# File lib/rough/route.rb, line 29
def load_path
  fake_defaults = @route.defaults.dup
  fake_defaults[:only_path] = true
  @route.segments.each { |s| fake_defaults[s.to_sym] = s }
  path = Rails.application.routes.url_for(fake_defaults)
  path || fail(InvalidRoute)
end
load_request_method() click to toggle source
# File lib/rough/route.rb, line 23
def load_request_method
  method_rule = @route.constraints[:request_method]
  methods = ActionDispatch::Request::RFC2616.select { |t| t =~ method_rule }
  methods.count == 1 ? methods.first : fail(InvalidRoute)
end