Class: Resque::Scheduler::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/resque/scheduler/util.rb

Class Method Summary collapse

Class Method Details

.classify(dashed_word) ⇒ Object


34
35
36
37
38
# File 'lib/resque/scheduler/util.rb', line 34

def self.classify(dashed_word)
  dashed_word.split('-').each do|part|
    part[0] = part[0].chr.upcase
  end.join
end

.constantize(camel_cased_word) ⇒ Object

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


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/resque/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] : []

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