Skip to content

Commit

Permalink
wrap the methods themselves in ruby versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
sethherr committed Nov 21, 2016
1 parent 650bc3e commit 4a910d2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
21 changes: 11 additions & 10 deletions lib/papertrail/cli.rb
Expand Up @@ -6,12 +6,6 @@
require 'papertrail'
require 'papertrail/connection'
require 'papertrail/cli_helpers'
if RUBY_VERSION < '1.9'
# Ruby 1.8 doesn't have json in the standard lib - so we have to use okjson
require 'papertrail/okjson'
else
require 'json'
end

module Papertrail
class Cli
Expand Down Expand Up @@ -199,11 +193,18 @@ def display_results(results)
$stdout.flush
end

def output_raw_json(hash)
if RUBY_VERSION < '1.9'
# Ruby 1.8 doesn't have json in the standard lib - so we have to use okjson, which is slow
if RUBY_VERSION < '1.9'
# Ruby 1.8 doesn't have json in the standard lib - so we have to use okjson
# This is really slow. Avoid it if possible (by upgrading ruby)
require 'papertrail/okjson'

def output_raw_json(hash)
$stdout.puts Papertrail::OkJson.encode(hash)
else
end
else
require 'json'

def output_raw_json(hash)
$stdout.puts JSON.generate(hash)
end
end
Expand Down
21 changes: 10 additions & 11 deletions lib/papertrail/http_client.rb
@@ -1,11 +1,5 @@
require 'delegate'
require 'net/https'
if RUBY_VERSION < '1.9'
# Ruby 1.8 doesn't have json in the standard lib - so we have to use okjson
require 'papertrail/okjson'
else
require 'json'
end

module Papertrail

Expand All @@ -16,19 +10,24 @@ def initialize(response)
super(response)
end

def body
if RUBY_VERSION < '1.9'
# This is really slow. Avoid it if possible (by upgrading ruby)
if RUBY_VERSION < '1.9'
# Ruby 1.8 doesn't have json in the standard lib - so we have to use okjson
# This is really slow. Avoid it if possible (by upgrading ruby)
require 'papertrail/okjson'

def body
if __getobj__.body.respond_to?(:force_encoding)
@body ||= Papertrail::OkJson.decode(__getobj__.body.dup.force_encoding('UTF-8'))
else
@body ||= Papertrail::OkJson.decode(__getobj__.body.dup)
end
else
end
else
require 'json'
def body
@body ||= JSON.parse(__getobj__.body.dup)
end
end

end

class HttpClient
Expand Down

0 comments on commit 4a910d2

Please sign in to comment.