class Grape::NamedRoutes::NamedRouteSeeker

Public Class Methods

new(app) click to toggle source
# File lib/grape/named_routes/named_route_seeker.rb, line 4
def initialize(app)
  @app = app
end

Public Instance Methods

find_endpoint(name) click to toggle source
# File lib/grape/named_routes/named_route_seeker.rb, line 8
def find_endpoint(name)
  name_to_endpoint_hash[name.to_sym]
end
find_endpoint!(name) click to toggle source
# File lib/grape/named_routes/named_route_seeker.rb, line 12
def find_endpoint!(name)
  fail NamedRouteNotFound.new(name), "Named route '#{name}' is missed." unless named_endpoint_present?(name)
  find_endpoint(name)
end
named_endpoint_present?(name) click to toggle source
# File lib/grape/named_routes/named_route_seeker.rb, line 18
def named_endpoint_present?(name)
  name_to_endpoint_hash.key?(name.to_sym)
end

Private Instance Methods

name_to_endpoint_hash() click to toggle source
# File lib/grape/named_routes/named_route_seeker.rb, line 30
def name_to_endpoint_hash
  @name_to_endpoint_hash ||= named_endpoints.inject({}) do |hash, endpoint|
    endpoint_name = endpoint.options[:route_options][:as].to_sym
    hash[endpoint_name] = endpoint
    hash
  end
end
named_endpoints() click to toggle source
# File lib/grape/named_routes/named_route_seeker.rb, line 24
def named_endpoints
  @named_endpoints ||= @app.endpoints.select do |endpoint|
    endpoint.options[:route_options].key?(:as)
  end
end