Module: BPS::Subscriber

Defined in:
lib/bps.rb,
lib/bps/subscriber/abstract.rb

Defined Under Namespace

Classes: Abstract

Class Method Summary collapse

Class Method Details

.register(*schemes, &resolver) ⇒ Object


34
35
36
37
38
39
# File 'lib/bps.rb', line 34

def self.register(*schemes, &resolver)
  @registry ||= {}
  schemes.each do |scheme|
    @registry[scheme] = resolver
  end
end

.resolve(url) ⇒ Object

Raises:

  • (ArgumentError)

41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bps.rb', line 41

def self.resolve(url)
  url = url.is_a?(::URI) ? url.dup : URI.parse(url)
  rsl = @registry[url.scheme]
  raise ArgumentError, "Unable to resolve subscriber #{url}, scheme #{url.scheme} is not registered" unless rsl

  opts = {}
  CGI.parse(url.query.to_s).each do |key, values|
    opts[key.to_sym] = values.first
  end
  rsl.call(url, **opts)
end