Class: RiderServer::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/rider_server/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(operation) ⇒ Response

Returns a new instance of Response.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rider_server/response.rb', line 14

def initialize(operation)
  raise "Operation ID cannot be nil" if operation["id"].nil?
  @op = operation["op"]

  @data = {
    "id" => operation["id"],
    "timestamp" => Time.now.strftime("%Y-%m-%d %H:%M:%S"),
    "status" => []
  }

  if operation["session"]
    @data["session"] = operation["session"]
  end
end

Instance Method Details

#[](name) ⇒ Object



49
50
51
# File 'lib/rider_server/response.rb', line 49

def [](name)
  @data[name]
end

#[]=(name, value) ⇒ Object



53
54
55
# File 'lib/rider_server/response.rb', line 53

def []=(name, value)
  @data[name] = value
end

#bencodeObject



65
66
67
# File 'lib/rider_server/response.rb', line 65

def bencode
  @data.bencode
end

#done?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/rider_server/response.rb', line 61

def done?
  @data["status"].include?("done")
end

#fetch(*args) ⇒ Object



41
42
43
# File 'lib/rider_server/response.rb', line 41

def fetch(*args)
  @data.fetch(*args)
end

#idObject



29
30
31
# File 'lib/rider_server/response.rb', line 29

def id
  @data["id"]
end

#inspectObject



69
70
71
# File 'lib/rider_server/response.rb', line 69

def inspect
  "#<RiderServer::Response:#{object_id} id=#{id} session=#{session} op=#{@op} status=#{@data["status"]}>"
end

#key?(name) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/rider_server/response.rb', line 45

def key?(name)
  @data.key? name
end

#sessionObject



33
34
35
# File 'lib/rider_server/response.rb', line 33

def session
  @data["session"]
end

#set(key, value) ⇒ Object



37
38
39
# File 'lib/rider_server/response.rb', line 37

def set(key, value)
  @data[key] = value
end

#status(*value) ⇒ Object



57
58
59
# File 'lib/rider_server/response.rb', line 57

def status(*value)
  @data["status"].concat(value)
end

#to_hObject



73
74
75
# File 'lib/rider_server/response.rb', line 73

def to_h
  @data
end