1
0
mirror of https://github.com/meineerde/rackstash.git synced 2026-01-31 17:27:13 +00:00

Allow to register complex URI schemes for Adapters

Most notably, we want to use the plus character in URI schemes. By only
checking the first character of the scheme registration, we can better
fullfil our contract and better distinguish between schemes and class
names of registered Adapters.
This commit is contained in:
Holger Just 2018-01-22 01:11:24 +01:00
parent e8bf2c31bd
commit 38a5c669a3
2 changed files with 8 additions and 1 deletions

View File

@ -53,7 +53,7 @@ module Rackstash
case matcher
when String
matcher = matcher.to_s
if matcher =~ /\A[a-z0-9]+\z/
if matcher =~ /\A[a-z0-9]/
# If the matcher is a lower-case string, we assume it is a URL
# scheme.
adapter_schemes[matcher.downcase] = adapter_class

View File

@ -210,6 +210,7 @@ describe Rackstash::Adapter do
context 'with a registered scheme' do
before do
described_class.register adapter, 'dummy'
described_class.register adapter, 'foo+dummy'
end
it 'creates an adapter from the scheme' do
@ -218,6 +219,12 @@ describe Rackstash::Adapter do
expect(described_class[raw_uri]).to be_an Rackstash::Adapter::BaseAdapter
end
it 'can use a complex scheme' do
raw_uri = 'foo+dummy://example.com'
expect(adapter).to receive(:from_uri).with(URI(raw_uri)).and_call_original
expect(described_class[raw_uri]).to be_an Rackstash::Adapter::BaseAdapter
end
it 'calls adapter.new if adapter.from_uri is not available' do
plain_adapter = Class.new(Rackstash::Adapter::BaseAdapter)
described_class.register plain_adapter, 'dummy'