Sha256: 967f51808f5f84d573a17d718af86471d9a6897324e0e7c20d5ba247c9d1a59d

Contents?: true

Size: 805 Bytes

Versions: 2

Compression:

Stored size: 805 Bytes

Contents

module Kthxbye
  module Helper

    def redis
      Kthxbye.redis
    end

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

    #
    # encode/decode code taken and modified from Resque 
    # (http://github.com/defunkt/resque/blob/master/lib/resque/helpers.rb)
    # 
    def encode( data )
      if defined? Yajl
        Yajl::Encoder.encode(data)
      else
        data.to_json
      end
    end

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kthxbye-1.0.1 lib/kthxbye/helper.rb
kthxbye-1.0.0 lib/kthxbye/helper.rb