Module: Kthxbye::Helper
- Included in:
- Kthxbye, Failure, Failure, Job, Job, Stats, Worker, Worker
- Defined in:
- lib/kthxbye/helper.rb
Overview
:nodoc: all
Instance Method Summary (collapse)
- - (Object) decode(data)
-
- (Object) encode(data)
encode/decode code taken and modified from Resque (github.com/defunkt/resque/blob/master/lib/resque/helpers.rb).
- - (Object) log(msg)
- - (Object) redis
Instance Method Details
- (Object) decode(data)
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kthxbye/helper.rb', line 24 def decode( data ) return unless data if defined? Yajl begin Yajl::Parser.parse( data, :check_utf8 => false ) rescue Yajl::ParseError end else begin JSON.parse( data ) rescue JSON::ParseError end end end |
- (Object) encode(data)
encode/decode code taken and modified from Resque (github.com/defunkt/resque/blob/master/lib/resque/helpers.rb)
16 17 18 19 20 21 22 |
# File 'lib/kthxbye/helper.rb', line 16 def encode( data ) if defined? Yajl Yajl::Encoder.encode(data) else data.to_json end end |
- (Object) log(msg)
6 7 8 9 10 |
# File 'lib/kthxbye/helper.rb', line 6 def log(msg) if Kthxbye::Config.[:verbose] puts "!! #{msg} - #{Time.now.strftime("%I:%M%p")}" end end |
- (Object) redis
3 4 5 |
# File 'lib/kthxbye/helper.rb', line 3 def redis Kthxbye.redis end |