aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Library/Homebrew/options.rb4
-rw-r--r--Library/Homebrew/tab.rb4
-rw-r--r--Library/Homebrew/test/test_options.rb4
-rw-r--r--Library/Homebrew/utils/json.rb25
4 files changed, 21 insertions, 16 deletions
diff --git a/Library/Homebrew/options.rb b/Library/Homebrew/options.rb
index 20c6009f6..c7d1acca2 100644
--- a/Library/Homebrew/options.rb
+++ b/Library/Homebrew/options.rb
@@ -15,10 +15,6 @@ class Option
end
alias_method :to_str, :to_s
- def to_json
- flag.inspect
- end
-
def <=>(other)
name <=> other.name
end
diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb
index 48f709113..29655b221 100644
--- a/Library/Homebrew/tab.rb
+++ b/Library/Homebrew/tab.rb
@@ -91,8 +91,8 @@ class Tab < OpenStruct
def to_json
Utils::JSON.dump({
- :used_options => used_options.to_a,
- :unused_options => unused_options.to_a,
+ :used_options => used_options.map(&:to_s),
+ :unused_options => unused_options.map(&:to_s),
:built_as_bottle => built_as_bottle,
:poured_from_bottle => poured_from_bottle,
:tapped_from => tapped_from,
diff --git a/Library/Homebrew/test/test_options.rb b/Library/Homebrew/test/test_options.rb
index 405ead73b..0cc16ff2e 100644
--- a/Library/Homebrew/test/test_options.rb
+++ b/Library/Homebrew/test/test_options.rb
@@ -14,10 +14,6 @@ class OptionTests < Test::Unit::TestCase
assert_equal "--foo", @option.to_str
end
- def test_to_json
- assert_equal %q{"--foo"}, @option.to_json
- end
-
def test_equality
foo = Option.new("foo")
bar = Option.new("bar")
diff --git a/Library/Homebrew/utils/json.rb b/Library/Homebrew/utils/json.rb
index f52881c84..0548a5cb3 100644
--- a/Library/Homebrew/utils/json.rb
+++ b/Library/Homebrew/utils/json.rb
@@ -1,4 +1,4 @@
-require 'vendor/multi_json'
+require 'vendor/okjson'
module Utils
module JSON
@@ -7,15 +7,28 @@ module Utils
Error = Class.new(StandardError)
def load(str)
- MultiJson.load(str)
- rescue MultiJson::DecodeError => e
+ Vendor::OkJson.decode(str)
+ rescue Vendor::OkJson::Error => e
raise Error, e.message
end
def dump(obj)
- MultiJson.dump(obj)
- rescue MultiJson::EncodeError => e
- raise Error, e.message
+ Vendor::OkJson.encode(stringify_keys(obj))
+ end
+
+ 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