Class: Fleet
- Inherits:
-
Object
show all
- Defined in:
- lib/fleet.rb
Defined Under Namespace
Classes: ClientError, ServerError
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Fleet
Returns a new instance of Fleet.
9
10
11
12
13
14
15
16
17
|
# File 'lib/fleet.rb', line 9
def initialize(options = {})
@host = options[:host] || "127.0.0.1"
@port = options[:port] || 3400
@timeout = options[:timeout] || 5
@password = options[:password]
@json_encoder = Yajl::Encoder
@json_parser = Yajl::Parser
connect
end
|
Instance Method Details
#close ⇒ Object
33
34
35
|
# File 'lib/fleet.rb', line 33
def close
disconnect
end
|
#query(q) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/fleet.rb', line 19
def query(q)
request = @json_encoder.encode(q)
response = write_and_read(request)
status, value = @json_parser.parse(response)
case status
when 0
value
when 1
raise ClientError, value
else
raise ServerError, value
end
end
|
#to_s ⇒ Object
37
38
39
|
# File 'lib/fleet.rb', line 37
def to_s
"FleetDB client connected to #{@host}:#{@port}"
end
|