mirror of
https://github.com/lostisland/faraday.git
synced 2025-10-06 00:03:36 -04:00
31 lines
597 B
Ruby
31 lines
597 B
Ruby
# frozen_string_literal: true
|
|
|
|
require 'monitor'
|
|
|
|
module Faraday
|
|
# AdapterRegistry registers adapter class names so they can be looked up by a
|
|
# String or Symbol name.
|
|
class AdapterRegistry
|
|
def initialize
|
|
@lock = Monitor.new
|
|
@constants = {}
|
|
end
|
|
|
|
def get(name)
|
|
klass = @lock.synchronize do
|
|
@constants[name]
|
|
end
|
|
return klass if klass
|
|
|
|
Object.const_get(name).tap { |c| set(c, name) }
|
|
end
|
|
|
|
def set(klass, name = nil)
|
|
name ||= klass.to_s
|
|
@lock.synchronize do
|
|
@constants[name] = klass
|
|
end
|
|
end
|
|
end
|
|
end
|