Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Push Connection into ThriftHelpers to prevent namespace pollution.

  • Loading branch information...
commit ab27b71883485abdcef6ab8955d902f7e7f7e3fc 1 parent d490a2b
Brandon Mitchell authored
View
28 lib/thrift_client/connection/base.rb
@@ -1,19 +1,21 @@
-module Connection
- class Base
- attr_accessor :transport, :server
+module ThriftHelpers
+ module Connection
+ class Base
+ attr_accessor :transport, :server
- def initialize(transport, transport_wrapper, server, timeout)
- @transport = transport
- @transport_wrapper = transport_wrapper
- @server = server
- @timeout = timeout
- end
+ def initialize(transport, transport_wrapper, server, timeout)
+ @transport = transport
+ @transport_wrapper = transport_wrapper
+ @server = server
+ @timeout = timeout
+ end
- def connect!
- raise NotImplementedError
- end
+ def connect!
+ raise NotImplementedError
+ end
- def close
+ def close
+ end
end
end
end
View
16 lib/thrift_client/connection/factory.rb
@@ -1,10 +1,12 @@
-module Connection
- class Factory
- def self.create(transport, transport_wrapper, server, timeout)
- if transport == Thrift::HTTPClientTransport
- Connection::HTTP.new(transport, transport_wrapper, server, timeout)
- else
- Connection::Socket.new(transport, transport_wrapper, server, timeout)
+module ThriftHelpers
+ module Connection
+ class Factory
+ def self.create(transport, transport_wrapper, server, timeout)
+ if transport == Thrift::HTTPClientTransport
+ Connection::HTTP.new(transport, transport_wrapper, server, timeout)
+ else
+ Connection::Socket.new(transport, transport_wrapper, server, timeout)
+ end
end
end
end
View
32 lib/thrift_client/connection/http.rb
@@ -1,18 +1,20 @@
-module Connection
- class HTTP < Base
- def connect!
- uri = parse_server(@server)
- @transport = Thrift::HTTPClientTransport.new(@server)
- http = Net::HTTP.new(uri.host, uri.port)
- http.use_ssl = uri.scheme == "https"
- http.get(uri.path)
- end
+module ThriftHelpers
+ module Connection
+ class HTTP < Base
+ def connect!
+ uri = parse_server(@server)
+ @transport = Thrift::HTTPClientTransport.new(@server)
+ http = Net::HTTP.new(uri.host, uri.port)
+ http.use_ssl = uri.scheme == "https"
+ http.get(uri.path)
+ end
- private
- def parse_server(server)
- uri = URI.parse(server)
- raise ArgumentError, 'Servers must start with http' unless uri.scheme =~ /^http/
- uri
+ private
+ def parse_server(server)
+ uri = URI.parse(server)
+ raise ArgumentError, 'Servers must start with http' unless uri.scheme =~ /^http/
+ uri
+ end
end
end
-end
View
34 lib/thrift_client/connection/socket.rb
@@ -1,22 +1,24 @@
-module Connection
- class Socket < Base
- def close
- @transport.close
- end
+module ThriftHelpers
+ module Connection
+ class Socket < Base
+ def close
+ @transport.close
+ end
- def connect!
- host, port = parse_server(@server)
- @transport = @transport.new(*[host, port.to_i, @timeout])
- @transport = @transport_wrapper.new(@transport) if @transport_wrapper
- @transport.open
- end
+ def connect!
+ host, port = parse_server(@server)
+ @transport = @transport.new(*[host, port.to_i, @timeout])
+ @transport = @transport_wrapper.new(@transport) if @transport_wrapper
+ @transport.open
+ end
- private
+ private
- def parse_server(server)
- host, port = server.to_s.split(":")
- raise ArgumentError, 'Servers must be in the form "host:port"' unless host and port
- [host, port]
+ def parse_server(server)
+ host, port = server.to_s.split(":")
+ raise ArgumentError, 'Servers must be in the form "host:port"' unless host and port
+ [host, port]
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.