Use OkJson directly
This commit is contained in:
parent
d8aab8cb04
commit
d6929f96a5
@ -15,10 +15,6 @@ class Option
|
|||||||
end
|
end
|
||||||
alias_method :to_str, :to_s
|
alias_method :to_str, :to_s
|
||||||
|
|
||||||
def to_json
|
|
||||||
flag.inspect
|
|
||||||
end
|
|
||||||
|
|
||||||
def <=>(other)
|
def <=>(other)
|
||||||
name <=> other.name
|
name <=> other.name
|
||||||
end
|
end
|
||||||
|
|||||||
@ -91,8 +91,8 @@ class Tab < OpenStruct
|
|||||||
|
|
||||||
def to_json
|
def to_json
|
||||||
Utils::JSON.dump({
|
Utils::JSON.dump({
|
||||||
:used_options => used_options.to_a,
|
:used_options => used_options.map(&:to_s),
|
||||||
:unused_options => unused_options.to_a,
|
:unused_options => unused_options.map(&:to_s),
|
||||||
:built_as_bottle => built_as_bottle,
|
:built_as_bottle => built_as_bottle,
|
||||||
:poured_from_bottle => poured_from_bottle,
|
:poured_from_bottle => poured_from_bottle,
|
||||||
:tapped_from => tapped_from,
|
:tapped_from => tapped_from,
|
||||||
|
|||||||
@ -14,10 +14,6 @@ class OptionTests < Test::Unit::TestCase
|
|||||||
assert_equal "--foo", @option.to_str
|
assert_equal "--foo", @option.to_str
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_to_json
|
|
||||||
assert_equal %q{"--foo"}, @option.to_json
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_equality
|
def test_equality
|
||||||
foo = Option.new("foo")
|
foo = Option.new("foo")
|
||||||
bar = Option.new("bar")
|
bar = Option.new("bar")
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
require 'vendor/multi_json'
|
require 'vendor/okjson'
|
||||||
|
|
||||||
module Utils
|
module Utils
|
||||||
module JSON
|
module JSON
|
||||||
@ -7,15 +7,28 @@ module Utils
|
|||||||
Error = Class.new(StandardError)
|
Error = Class.new(StandardError)
|
||||||
|
|
||||||
def load(str)
|
def load(str)
|
||||||
MultiJson.load(str)
|
Vendor::OkJson.decode(str)
|
||||||
rescue MultiJson::DecodeError => e
|
rescue Vendor::OkJson::Error => e
|
||||||
raise Error, e.message
|
raise Error, e.message
|
||||||
end
|
end
|
||||||
|
|
||||||
def dump(obj)
|
def dump(obj)
|
||||||
MultiJson.dump(obj)
|
Vendor::OkJson.encode(stringify_keys(obj))
|
||||||
rescue MultiJson::EncodeError => e
|
end
|
||||||
raise Error, e.message
|
|
||||||
|
def stringify_keys(obj)
|
||||||
|
case obj
|
||||||
|
when Array
|
||||||
|
obj.map { |val| stringify_keys(val) }
|
||||||
|
when Hash
|
||||||
|
obj.inject({}) do |result, (key, val)|
|
||||||
|
key = key.respond_to?(:to_s) ? key.to_s : key
|
||||||
|
val = stringify_keys(val)
|
||||||
|
result.merge!(key => val)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
obj
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user