`QueueAdapters` does the lookup

This commit is contained in:
Tamir Duberstein 2015-03-12 10:28:16 -07:00
parent ccf8678cec
commit 9832e17c3c
2 changed files with 9 additions and 5 deletions

View File

@ -31,7 +31,7 @@ module ActiveJob
def interpret_adapter(name_or_adapter_or_class) def interpret_adapter(name_or_adapter_or_class)
case name_or_adapter_or_class case name_or_adapter_or_class
when Symbol, String when Symbol, String
load_adapter(name_or_adapter_or_class) ActiveJob::QueueAdapters.lookup(name_or_adapter_or_class).new
else else
if queue_adapter?(name_or_adapter_or_class) if queue_adapter?(name_or_adapter_or_class)
name_or_adapter_or_class name_or_adapter_or_class
@ -56,10 +56,6 @@ module ActiveJob
def queue_adapter_class?(object) def queue_adapter_class?(object)
object.is_a?(Class) && QUEUE_ADAPTER_METHODS.all? { |meth| object.public_method_defined?(meth) } object.is_a?(Class) && QUEUE_ADAPTER_METHODS.all? { |meth| object.public_method_defined?(meth) }
end end
def load_adapter(name)
ActiveJob::QueueAdapters.const_get(name.to_s.camelize + 'Adapter').new
end
end end
end end
end end

View File

@ -48,5 +48,13 @@ module ActiveJob
autoload :SneakersAdapter autoload :SneakersAdapter
autoload :SuckerPunchAdapter autoload :SuckerPunchAdapter
autoload :TestAdapter autoload :TestAdapter
ADAPTER = 'Adapter'.freeze
class << self
def lookup(name)
const_get(name.to_s.camelize << ADAPTER)
end
end
end end
end end