diff --git a/lib/que.rb b/lib/que.rb index 658c2f4a..7670c87d 100644 --- a/lib/que.rb +++ b/lib/que.rb @@ -129,6 +129,15 @@ def disable_prepared_statements @disable_prepared_statements || false end + def constantize(camel_cased_word) + if camel_cased_word.respond_to?(:constantize) + # Use ActiveSupport's version if it exists. + camel_cased_word.constantize + else + string.split('::').inject(Object, &:const_get) + end + end + # A helper method to manage transactions, used mainly by the migration # system. It's available for general use, but if you're using an ORM that # provides its own transaction helper, be sure to use that instead, or the diff --git a/lib/que/job.rb b/lib/que/job.rb index 2af05159..45fcede3 100644 --- a/lib/que/job.rb +++ b/lib/que/job.rb @@ -142,7 +142,7 @@ def work(queue = '') private def class_for(string) - string.split('::').inject(Object, &:const_get) + Que.constantize(string) end end end