Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
remove delegation
Browse files Browse the repository at this point in the history
  • Loading branch information
chancefeick committed Sep 29, 2016
1 parent fba1555 commit ea33635
Showing 1 changed file with 12 additions and 33 deletions.
45 changes: 12 additions & 33 deletions lib/librato/metrics/smart_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,21 @@ class SmartJSON
extend SingleForwardable

if defined?(::MultiJson)
if RUBY_VERSION <= "2.3.0"
def self.read(json)
# MultiJSON >= 1.3.0
if MultiJson.respond_to?(:load)
def_delegator MultiJson, :load, :read
MultiJson.load(json)
else
def_delegator MultiJson, :decode, :read
MultiJson.decode(json)
end
end

def self.write(json)
# MultiJSON <= 1.2.0
if MultiJson.respond_to?(:dump)
def_delegator MultiJson, :dump, :write
MultiJson.dump(json)
else
def_delegator MultiJson, :encode, :write
end
else
def self.read(json)
# MultiJSON >= 1.3.0
if MultiJson.respond_to?(:load)
MultiJson.load(json)
else
MultiJson.decode(json)
end
end

def self.write(json)
# MultiJSON <= 1.2.0
if MultiJson.respond_to?(:dump)
MultiJson.dump(json)
else
MultiJson.encode(json)
end
MultiJson.encode(json)
end
end

Expand All @@ -44,17 +28,12 @@ def self.handler
else
require "json"

if RUBY_VERSION <= "2.3.0"
def_delegator JSON, :parse, :read
def_delegator JSON, :generate, :write
else
def self.read(json)
JSON.parse(json)
end
def self.read(json)
JSON.parse(json)
end

def self.write(json)
JSON.generate(json)
end
def self.write(json)
JSON.generate(json)
end

def self.handler
Expand Down

0 comments on commit ea33635

Please sign in to comment.