You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: endpoint_lookup.rb
    path of file: ./repos/sequencescape/app/api/core/endpoint/basic_handler
    
    the code of the file until where you have to start completion: # frozen_string_literal: true
module Core::Endpoint::BasicHandler::EndpointLookup
  EndpointError = Class.new(StandardError)
  MissingEndpoint = Class.new(EndpointError)

  def endpoint_for(model, root = model)
    raise EndpointError, "Incorrect hierarchy for #{root.inspect}" if model.nil?
    raise 
    
  def endpoint_for(model, root = model)
    raise EndpointError, "Incorrect hierarchy for #{root.inspect}" if model.nil?
    raise MissingEndpoint, "No endpoint for the model #{root.inspect}" if model == ActiveRecord::Base

    endpoint_name = ['Endpoints', model.name.pluralize].join('::')

    begin
      endpoint_name.constantize
    rescue NameError => e
      # Some performance improvement can be made by storing the class that is found for those
      # that are missing.  Meaning the next time we shouldn't be coming through this path.
      cache_endpoint_as(endpoint_name, endpoint_for(model.superclass, root))
    end