Class: Trexrb

Inherits:
Object
  • Object
show all
Defined in:
lib/trexrb.rb,
lib/trexrb/version.rb

Constant Summary collapse

DEFAULT_HOST =
'localhost'
DEFAULT_PORT =
4040
VERSION =
"0.1.2"

Instance Method Summary collapse

Constructor Details

#initialize(host = nil, port = nil) ⇒ Trexrb

Returns a new instance of Trexrb.



9
10
11
12
# File 'lib/trexrb.rb', line 9

def initialize(host = nil, port = nil)
  @host = host || DEFAULT_HOST
  @port = port || DEFAULT_PORT
end

Instance Method Details

#get(key) ⇒ Object Also known as: []



14
15
16
17
18
19
20
# File 'lib/trexrb.rb', line 14

def get(key)
  with_connection do |conn|
    conn.print Request.new.get(key)

    Response.new(conn.read).body
  end
end

#keysObject



30
31
32
33
34
35
36
37
# File 'lib/trexrb.rb', line 30

def keys
  with_connection do |conn|
    conn.print Request.new.list
    result = Response.new(conn.read).body

    result || []
  end
end

#set(key, value) ⇒ Object Also known as: []=



22
23
24
25
26
27
28
# File 'lib/trexrb.rb', line 22

def set(key, value)
  with_connection do |conn|
    conn.print Request.new.set(key, value)

    Response.new(conn.read).body
  end
end