class ResqueAdmin::Scheduler::Util

Public Class Methods

classify(dashed_word) click to toggle source
# File lib/resque_admin/scheduler/util.rb, line 34
def self.classify(dashed_word)
  dashed_word.split('-').map(&:capitalize).join
end
constantize(camel_cased_word) click to toggle source

In order to upgrade to resque_admin(1.25) which has deprecated following methods, we just added these usefull helpers back to use in ResqueAdmin Scheduler. refer to: github.com/resque_admin/resque_admin-scheduler/pull/273

# File lib/resque_admin/scheduler/util.rb, line 11
def self.constantize(camel_cased_word)
  camel_cased_word = camel_cased_word.to_s

  if camel_cased_word.include?('-')
    camel_cased_word = classify(camel_cased_word)
  end

  names = camel_cased_word.split('::')
  names.shift if names.empty? || names.first.empty?

  constant = Object
  names.each do |name|
    args = Module.method(:const_get).arity != 1 ? [false] : []

    constant = if constant.const_defined?(name, *args)
                 constant.const_get(name)
               else
                 constant.const_missing(name)
               end
  end
  constant
end