Skip to content

Commit

Permalink
Implement jrjackson -> jr_jackson alias for back-compat
Browse files Browse the repository at this point in the history
  • Loading branch information
rwz committed Mar 19, 2013
1 parent b36dc91 commit aa50ab8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/multi_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def default_options=(value)
self.load_options = self.dump_options = value
end

ALIASES = {
'jrjackson' => :jr_jackson
}

REQUIREMENT_MAP = [
['oj', :oj],
['yajl', :yajl],
Expand Down Expand Up @@ -88,8 +92,10 @@ def use(new_adapter)
def load_adapter(new_adapter)
case new_adapter
when String, Symbol
new_adapter = ALIASES.fetch(new_adapter.to_s, new_adapter)
require "multi_json/adapters/#{new_adapter}"
MultiJson::Adapters.const_get(:"#{new_adapter.to_s.split('_').map{|s| s.capitalize}.join('')}")
klass_name = new_adapter.to_s.split('_').map(&:capitalize) * ''
MultiJson::Adapters.const_get(klass_name)
when NilClass, FalseClass
load_adapter default_adapter
when Class, Module
Expand Down
17 changes: 17 additions & 0 deletions spec/multi_json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,21 @@
it_behaves_like 'JSON-like adapter', adapter
end
end

describe 'aliases' do
if jruby?
describe 'jrjackson' do
after{ expect(MultiJson.adapter).to eq(MultiJson::Adapters::JrJackson) }

it 'allows jrjackson alias as symbol' do
expect{ MultiJson.use :jrjackson }.not_to raise_error
end

it 'allows jrjackson alias as string' do
expect{ MultiJson.use 'jrjackson' }.not_to raise_error
end

end
end
end
end

0 comments on commit aa50ab8

Please sign in to comment.