class GlobalID::Locator::BaseLocator

def find_records(model_class, ids, options)

def find_records(model_class, ids, options)
  model_class = model_class.includes(options[:includes]) if options[:includes]
  if options[:ignore_missing]
    model_class.where(primary_key(model_class) => ids)
  else
    model_class.find(ids)
  end
end

def locate(gid, options = {})

def locate(gid, options = {})
  return unless model_id_is_valid?(gid)
  model_class = gid.model_class
  model_class = model_class.includes(options[:includes]) if options[:includes]
  model_class.find gid.model_id
end

def locate_many(gids, options = {})

def locate_many(gids, options = {})
  ids_by_model = Hash.new { |hash, key| hash[key] = [] }
  gids.each do |gid|
    next unless model_id_is_valid?(gid)
    ids_by_model[gid.model_class] << gid.model_id
  end
  records_by_model_name_and_id = {}
  ids_by_model.each do |model, ids|
    records = find_records(model, ids, ignore_missing: options[:ignore_missing], includes: options[:includes])
    records_by_id = records.index_by do |record|
      record.id.is_a?(Array) ? record.id.map(&:to_s) : record.id.to_s
    end
    records_by_model_name_and_id[model.name] = records_by_id
  end
  gids.filter_map { |gid| records_by_model_name_and_id[gid.model_name][gid.model_id] }
end

def model_id_is_valid?(gid)

def model_id_is_valid?(gid)
  Array(gid.model_id).size == Array(primary_key(gid.model_class)).size
end

def primary_key(model_class)

def primary_key(model_class)
  model_class.respond_to?(:primary_key) ? model_class.primary_key : :id
end