class Dizby::ProtocolManager
Public Class Methods
add_protocol(klass)
click to toggle source
# File lib/dizby/protocol/manager.rb, line 14 def add_protocol(klass) @protocols << klass end
open_client(server, client_args)
click to toggle source
# File lib/dizby/protocol/manager.rb, line 18 def open_client(server, client_args) call_refined(:client, client_args, server) end
open_server(server_args)
click to toggle source
# File lib/dizby/protocol/manager.rb, line 22 def open_server(server_args) call_refined(:server, server_args) end
spawn_server(server, spawn_args)
click to toggle source
# File lib/dizby/protocol/manager.rb, line 26 def spawn_server(server, spawn_args) call_refined(:spawn, spawn_args, server) end
Private Class Methods
call_refined(refiner, base_args, *bonus_args)
click to toggle source
# File lib/dizby/protocol/manager.rb, line 32 def call_refined(refiner, base_args, *bonus_args) klass = get_protocol(base_args.uri) refined = refine_protocol(klass, refiner) args = get_arguments(refined, base_args.uri) refined.call(base_args, *bonus_args, args) end
get_arguments(refined, uri)
click to toggle source
# File lib/dizby/protocol/manager.rb, line 56 def get_arguments(refined, uri) raise BadURI, "can't parse uri: #{uri}" unless refined.regex =~ uri $~[1..-1] end
get_protocol(uri)
click to toggle source
# File lib/dizby/protocol/manager.rb, line 39 def get_protocol(uri) scheme = '' if uri.empty? scheme ||= uri.split(':').first raise BadScheme, "can't retrieve scheme: #{uri}" unless scheme protocol = @protocols.find { |klass| klass.scheme == scheme } protocol || raise(BadScheme, "scheme not found: #{scheme}") end
refine_protocol(protocol, refinement)
click to toggle source
# File lib/dizby/protocol/manager.rb, line 48 def refine_protocol(protocol, refinement) refined = protocol.get_refinement(refinement) return refined if refined raise NotImplementedError, "#{refinement} refinement not supported for #{protocol}" end