Module: Kthxbye::Helper

Included in:
Kthxbye, Failure, Failure, Job, Job, Worker, Worker
Defined in:
lib/kthxbye/helper.rb

Overview

:nodoc: all

Instance Method Summary collapse

Instance Method Details

#decode(data) ⇒ Object



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

#encode(data) ⇒ Object

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

#log(msg) ⇒ Object



6
7
8
9
10
# File 'lib/kthxbye/helper.rb', line 6

def log(msg)
  if Kthxbye::Config.options[:verbose]
    puts "!! #{msg} - #{Time.now.strftime("%I:%M%p")}"
  end
end

#redisObject



3
4
5
# File 'lib/kthxbye/helper.rb', line 3

def redis
  Kthxbye.redis
end