Class: Dizby::ProtocolManager
- Inherits:
-
Object
- Object
- Dizby::ProtocolManager
- Defined in:
- lib/dizby/protocol/manager.rb
Class Method Summary collapse
- .add_protocol(klass)
- .call_refined(uri, refiner, *base_args) private
- .get_arguments(refined, uri) private
- .get_protocol(uri) private
- .open_client(server, uri)
- .open_server(uri, front, config)
- .refine_protocol(protocol, refinement) private
- .spawn_server(server, command, uri)
Class Method Details
.add_protocol(klass)
14 15 16 |
# File 'lib/dizby/protocol/manager.rb', line 14 def add_protocol(klass) @protocols << klass end |
.call_refined(uri, refiner, *base_args) (private)
32 33 34 35 36 37 |
# File 'lib/dizby/protocol/manager.rb', line 32 def call_refined(uri, refiner, *base_args) klass = get_protocol(uri) refined = refine_protocol(klass, refiner) args = get_arguments(refined, uri) refined.call(*base_args, args) end |
.get_arguments(refined, uri) (private)
59 60 61 62 63 |
# File 'lib/dizby/protocol/manager.rb', line 59 def get_arguments(refined, uri) fail BadURI, "can't parse uri: #{uri}" unless refined.regex =~ uri $~[1..-1] end |
.get_protocol(uri) (private)
39 40 41 42 43 44 45 46 |
# File 'lib/dizby/protocol/manager.rb', line 39 def get_protocol(uri) scheme = '' if uri.empty? scheme ||= uri.split(':').first fail BadScheme, "can't retrieve scheme: #{uri}" unless scheme protocol = @protocols.find { |klass| klass.scheme == scheme } protocol || fail(BadScheme, "scheme not found: #{scheme}") end |
.open_client(server, uri)
18 19 20 |
# File 'lib/dizby/protocol/manager.rb', line 18 def open_client(server, uri) call_refined(uri, :client, server) end |
.open_server(uri, front, config)
22 23 24 |
# File 'lib/dizby/protocol/manager.rb', line 22 def open_server(uri, front, config) call_refined(uri, :server, front, config) end |
.refine_protocol(protocol, refinement) (private)
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/dizby/protocol/manager.rb', line 48 def refine_protocol(protocol, refinement) refined = protocol.get_refinement(refinement) unless refined fail NotImplementedError, "#{refinement} refinement not supported for #{protocol}" end refined end |
.spawn_server(server, command, uri)
26 27 28 |
# File 'lib/dizby/protocol/manager.rb', line 26 def spawn_server(server, command, uri) call_refined(uri, :spawn, server, command) end |