Module: Resque::Helpers
- Included in:
- Resque, Job, Job, QueueStats, QueueStats, Stat, Worker, Worker
- Defined in:
- lib/resque/helpers.rb
Overview
Methods used by various classes in Resque.
Defined Under Namespace
Classes: DecodeException
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.
-
#decode(object) ⇒ Object
Given a string, returns a Ruby object.
-
#encode(object) ⇒ Object
Given a Ruby object, returns a string suitable for storage in a queue.
-
#mongo ⇒ Object
Direct access to the Redis instance.
- #mongo_queues ⇒ Object
- #mongo_stats ⇒ Object
- #mongo_workers ⇒ Object
Instance Method Details
#classify(dashed_word) ⇒ Object
Given a word with dashes, returns a camel cased version of it.
classify(‘job-name’) # => ‘JobName’
51 52 53 |
# File 'lib/resque/helpers.rb', line 51 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
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/resque/helpers.rb', line 58 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 |
#decode(object) ⇒ Object
Given a string, returns a Ruby object.
38 39 40 41 42 43 44 45 46 |
# File 'lib/resque/helpers.rb', line 38 def decode(object) return unless object begin ::MultiJson.decode(object) rescue ::MultiJson::DecodeError => e raise DecodeException, e end end |
#encode(object) ⇒ Object
Given a Ruby object, returns a string suitable for storage in a queue.
33 34 35 |
# File 'lib/resque/helpers.rb', line 33 def encode(object) ::MultiJson.encode(object) end |
#mongo ⇒ Object
Direct access to the Redis instance.
15 16 17 |
# File 'lib/resque/helpers.rb', line 15 def mongo Resque.mongo end |
#mongo_queues ⇒ Object
27 28 29 |
# File 'lib/resque/helpers.rb', line 27 def mongo_queues Resque.mongo_queues end |
#mongo_stats ⇒ Object
23 24 25 |
# File 'lib/resque/helpers.rb', line 23 def mongo_stats Resque.mongo_stats end |
#mongo_workers ⇒ Object
19 20 21 |
# File 'lib/resque/helpers.rb', line 19 def mongo_workers Resque.mongo_workers end |