Skip to content

Commit aa50ab8

Browse files
committed
Implement jrjackson -> jr_jackson alias for back-compat
1 parent b36dc91 commit aa50ab8

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

lib/multi_json.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def default_options=(value)
2626
self.load_options = self.dump_options = value
2727
end
2828

29+
ALIASES = {
30+
'jrjackson' => :jr_jackson
31+
}
32+
2933
REQUIREMENT_MAP = [
3034
['oj', :oj],
3135
['yajl', :yajl],
@@ -88,8 +92,10 @@ def use(new_adapter)
8892
def load_adapter(new_adapter)
8993
case new_adapter
9094
when String, Symbol
95+
new_adapter = ALIASES.fetch(new_adapter.to_s, new_adapter)
9196
require "multi_json/adapters/#{new_adapter}"
92-
MultiJson::Adapters.const_get(:"#{new_adapter.to_s.split('_').map{|s| s.capitalize}.join('')}")
97+
klass_name = new_adapter.to_s.split('_').map(&:capitalize) * ''
98+
MultiJson::Adapters.const_get(klass_name)
9399
when NilClass, FalseClass
94100
load_adapter default_adapter
95101
when Class, Module

spec/multi_json_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,21 @@
163163
it_behaves_like 'JSON-like adapter', adapter
164164
end
165165
end
166+
167+
describe 'aliases' do
168+
if jruby?
169+
describe 'jrjackson' do
170+
after{ expect(MultiJson.adapter).to eq(MultiJson::Adapters::JrJackson) }
171+
172+
it 'allows jrjackson alias as symbol' do
173+
expect{ MultiJson.use :jrjackson }.not_to raise_error
174+
end
175+
176+
it 'allows jrjackson alias as string' do
177+
expect{ MultiJson.use 'jrjackson' }.not_to raise_error
178+
end
179+
180+
end
181+
end
182+
end
166183
end

0 commit comments

Comments
 (0)