Skip to content

Commit

Permalink
Hardwire multi_json backend
Browse files Browse the repository at this point in the history
The `multi_json` gem dynamically selects a JSON implementation from a list of
candidates. Since we cannot control which gems are installed on a user's
machine, this patch hardwires `multi_json` to use the included copy of `ok_json`.

`ok_json` is a pure-Ruby JSON encoder/decoder that is bundled with
`multi_json`. `ok_json` may not be as fast as other choices, but speed is not
critical for our application.

Closes Homebrew#8574.

Signed-off-by: Charlie Sharpsteen <source@sharpsteen.net>
  • Loading branch information
Sharpie committed Nov 14, 2011
1 parent cfd9d50 commit 30745b9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 14 deletions.
14 changes: 1 addition & 13 deletions Library/Homebrew/vendor/multi_json.rb
Expand Up @@ -22,18 +22,6 @@ def engine
# if any engines are already loaded, then checks # if any engines are already loaded, then checks
# to see which are installed if none are loaded. # to see which are installed if none are loaded.
def default_engine def default_engine
return :yajl if defined?(::Yajl)
return :json_gem if defined?(::JSON)

REQUIREMENT_MAP.each do |(library, engine)|
begin
require library
return engine
rescue LoadError
next
end
end

:ok_json :ok_json
end end


Expand All @@ -47,7 +35,7 @@ def default_engine
def engine=(new_engine) def engine=(new_engine)
case new_engine case new_engine
when String, Symbol when String, Symbol
require "multi_json/engines/#{new_engine}" require "vendor/multi_json/engines/#{new_engine}"
@engine = MultiJson::Engines.const_get("#{new_engine.to_s.split('_').map{|s| s.capitalize}.join('')}") @engine = MultiJson::Engines.const_get("#{new_engine.to_s.split('_').map{|s| s.capitalize}.join('')}")
when Class when Class
@engine = new_engine @engine = new_engine
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/vendor/multi_json/engines/ok_json.rb
@@ -1,4 +1,4 @@
require "multi_json/vendor/ok_json" unless defined?(::OkJson) require "vendor/multi_json/vendor/ok_json" unless defined?(::OkJson)


module MultiJson module MultiJson
module Engines module Engines
Expand Down

0 comments on commit 30745b9

Please sign in to comment.