module Grape::NamedRoutes::NamedPathHelper

Public Instance Methods

find_endpoint(route_name) click to toggle source
# File lib/grape/named_routes/named_path_helper.rb, line 9
def find_endpoint(route_name)
  named_route_seeker.find_endpoint(route_name)
end
find_endpoint!(route_name) click to toggle source
# File lib/grape/named_routes/named_path_helper.rb, line 13
def find_endpoint!(route_name)
  named_route_seeker.find_endpoint!(route_name)
end
get_named_path(route_name, route_params = {}) click to toggle source
# File lib/grape/named_routes/named_path_helper.rb, line 4
def get_named_path(route_name, route_params = {})
  endpoint = named_route_seeker.find_endpoint!(route_name)
  NamedRoutes::PathCompiler.compile_path(endpoint.routes.first, route_params)
end
method_missing(method_name, *arguments) click to toggle source
Calls superclass method
# File lib/grape/named_routes/named_path_helper.rb, line 17
def method_missing(method_name, *arguments)
  if method_is_named_path?(method_name)
    route_name = method_name.to_s.sub(/_path$/, '')
    get_named_path(route_name, arguments.first || {})
  else
    super
  end
end
respond_to_missing?(method_name, include_private = false) click to toggle source
Calls superclass method
# File lib/grape/named_routes/named_path_helper.rb, line 26
def respond_to_missing?(method_name, include_private = false)
  method_is_named_path?(method_name) || super
end

Private Instance Methods

method_is_named_path?(method_name) click to toggle source
# File lib/grape/named_routes/named_path_helper.rb, line 36
def method_is_named_path?(method_name)
  if method_name.to_s.end_with?('_path')
    route_name = method_name.to_s.sub(/_path$/, '')
    return true if named_route_seeker.named_endpoint_present?(route_name)
  end
  false
end
named_route_seeker() click to toggle source
# File lib/grape/named_routes/named_path_helper.rb, line 32
def named_route_seeker
  @named_route_seeker ||= NamedRoutes::NamedRouteSeeker.new(self)
end