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

Commit

Permalink
remove define_singleton_method
Browse files Browse the repository at this point in the history
  • Loading branch information
chancefeick committed Aug 24, 2016
1 parent d1a603d commit 3dd5291
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions lib/librato/metrics/smart_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,34 @@ module Metrics
class SmartJSON
extend SingleForwardable

@handler =
if defined?(::MultiJson)
# MultiJSON >= 1.3.0
if MultiJson.respond_to?(:load)
def_delegator MultiJson, :load, :read
else
def_delegator MultiJson, :decode, :read
end
if defined?(::MultiJson)
# MultiJSON >= 1.3.0
if MultiJson.respond_to?(:load)
def_delegator MultiJson, :load, :read
else
def_delegator MultiJson, :decode, :read
end

# MultiJSON <= 1.2.0
if MultiJson.respond_to?(:dump)
def_delegator MultiJson, :dump, :write
else
def_delegator MultiJson, :encode, :write
end
# MultiJSON <= 1.2.0
if MultiJson.respond_to?(:dump)
def_delegator MultiJson, :dump, :write
else
def_delegator MultiJson, :encode, :write
end

def self.handler
:multi_json
else
require "json/ext"
end
else
require "json"

def_delegator JSON, :parse, :read
def_delegator JSON, :generate, :write
def_delegator JSON, :parse, :read
def_delegator JSON, :generate, :write

def self.handler
:json
end

define_singleton_method(:handler) { @handler }
end
end
end
end

0 comments on commit 3dd5291

Please sign in to comment.