Sha256: 3829d05ff2c993b36518993f6dcfa474ceeda147e07a5cf8cbb72cd07d9d4596

Contents?: true

Size: 816 Bytes

Versions: 9

Compression:

Stored size: 816 Bytes

Contents

module Kthxbye
  module Helper #:nodoc: all
    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

9 entries across 9 versions & 1 rubygems

Version Path
kthxbye-1.3.2 lib/kthxbye/helper.rb
kthxbye-1.3.0 lib/kthxbye/helper.rb
kthxbye-1.2.1 lib/kthxbye/helper.rb
kthxbye-1.2.0 lib/kthxbye/helper.rb
kthxbye-1.1.1 lib/kthxbye/helper.rb
kthxbye-1.1.0 lib/kthxbye/helper.rb
kthxbye-1.0.5 lib/kthxbye/helper.rb
kthxbye-1.0.4 lib/kthxbye/helper.rb
kthxbye-1.0.2 lib/kthxbye/helper.rb