Module: MongoJob::Helpers
- Included in:
- Model::Job, Model::Job, Worker, Worker
- Defined in:
- lib/mongojob/helpers.rb
Instance Method Summary collapse
-
#classify(dashed_word) ⇒ Object
Given a word with dashes, returns a camel cased version of it.
-
#constantize(camel_cased_word) ⇒ Object
Given a camel cased word, returns the constant it represents.
Instance Method Details
#classify(dashed_word) ⇒ Object
Given a word with dashes, returns a camel cased version of it.
classify(‘job-name’) # => ‘JobName’
7 8 9 |
# File 'lib/mongojob/helpers.rb', line 7 def classify(dashed_word) dashed_word.split('-').each { |part| part[0] = part[0].chr.upcase }.join end |
#constantize(camel_cased_word) ⇒ Object
Given a camel cased word, returns the constant it represents
constantize(‘JobName’) # => JobName
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mongojob/helpers.rb', line 14 def 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| constant = constant.const_get(name) || constant.const_missing(name) end constant end |