aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/utils/json.rb
diff options
context:
space:
mode:
authorJack Nagel2013-06-22 16:51:08 -0500
committerJack Nagel2013-06-22 21:34:02 -0500
commit083b3c84d08571dda76e4d9ec553492ca60b8db3 (patch)
tree3f6b9dd8f3d128116a503a42e220ab664d39911c /Library/Homebrew/utils/json.rb
parentc4272a25cc1e8cd85acadb52db551cad2a5824cb (diff)
downloadbrew-083b3c84d08571dda76e4d9ec553492ca60b8db3.tar.bz2
Add Utils::JSON to wrap the JSON implementation
Diffstat (limited to 'Library/Homebrew/utils/json.rb')
-rw-r--r--Library/Homebrew/utils/json.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/Library/Homebrew/utils/json.rb b/Library/Homebrew/utils/json.rb
new file mode 100644
index 000000000..f52881c84
--- /dev/null
+++ b/Library/Homebrew/utils/json.rb
@@ -0,0 +1,21 @@
+require 'vendor/multi_json'
+
+module Utils
+ module JSON
+ extend self
+
+ Error = Class.new(StandardError)
+
+ def load(str)
+ MultiJson.load(str)
+ rescue MultiJson::DecodeError => e
+ raise Error, e.message
+ end
+
+ def dump(obj)
+ MultiJson.dump(obj)
+ rescue MultiJson::EncodeError => e
+ raise Error, e.message
+ end
+ end
+end