Skip to content

Commit

Permalink
Merge pull request #19 from disbelief/constantize-worker_class-in-mid…
Browse files Browse the repository at this point in the history
…dleware

Rely on Sidekiq's String#constantize extension instead of rolling our own
  • Loading branch information
mhenrixon committed Aug 28, 2013
2 parents c046029 + 0c26b77 commit 098c20e
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions lib/sidekiq-unique-jobs/middleware/client/unique_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,12 @@ def call(worker_class, item, queue)

# Attempt to constantize a string worker_class argument, always
# failing back to the original argument.
# Duplicates Rails' String.constantize logic for non-Rails cases.
def worker_class_constantize(worker_class)
if worker_class.is_a?(String)
if worker_class.respond_to?(:constantize)
worker_class.constantize
else
# duplicated logic from Rails 3.2.13 ActiveSupport::Inflector
# https://github.com/rails/rails/blob/9e0b3fc7cfba43af55377488f991348e2de24515/activesupport/lib/active_support/inflector/methods.rb#L213
names = worker_class.split('::')
names.shift if names.empty? || names.first.empty?
constant = Object
names.each do |name|
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
end
constant
end
worker_class.constantize rescue worker_class
else
worker_class
end
rescue
worker_class
end

end
Expand Down

0 comments on commit 098c20e

Please sign in to comment.