Class: Groonga::Client::Response::Base
- Inherits:
-
Object
- Object
- Groonga::Client::Response::Base
- Defined in:
- lib/groonga/client/response/base.rb
Direct Known Subclasses
CacheLimit, Check, ClearLock, ColumnCreate, ColumnList, ColumnRemove, ColumnRename, Defrag, Delete, Dump, Error, Load, LogLevel, LogPut, LogReopen, Quit, Register, Select, Status, TableCreate, TableList
Instance Attribute Summary collapse
-
#body ⇒ ::Hash
The body of response.
-
#command ⇒ Groonga::Command
The command for the request.
-
#header ⇒ ::Array<Integer, Float, Float>
The header of response.
-
#raw ⇒ String
The unparsed response.
Class Method Summary collapse
Instance Method Summary collapse
-
#elapsed_time ⇒ Time
The elapsed time of the request.
-
#initialize(command, header, body) ⇒ Base
constructor
A new instance of Base.
-
#start_time ⇒ Time
The time of the request is accepted.
-
#status_code ⇒ Integer
The status code of the response.
-
#success? ⇒ Boolean
true
if the request is processed successfully,false
otherwise.
Constructor Details
#initialize(command, header, body) ⇒ Base
Returns a new instance of Base.
139 140 141 142 143 144 |
# File 'lib/groonga/client/response/base.rb', line 139 def initialize(command, header, body) self.command = command self.header = header self.body = body self.raw = nil end |
Instance Attribute Details
#body ⇒ ::Hash
Returns The body of response. Its content is depends on command.
134 135 136 |
# File 'lib/groonga/client/response/base.rb', line 134 def body @body end |
#command ⇒ Groonga::Command
Returns The command for the request.
120 121 122 |
# File 'lib/groonga/client/response/base.rb', line 120 def command @command end |
#header ⇒ ::Array<Integer, Float, Float>
Returns The header of response.
It consists of [return_code, start_time, elapsed_time_in_seconds]
for success case.
It consists of
[return_code, start_time, elapsed_time_in_seconds, error_message, error_location]
for error case.
129 130 131 |
# File 'lib/groonga/client/response/base.rb', line 129 def header @header end |
#raw ⇒ String
Returns The unparsed response. It may be JSON, XML or groonga command format.
137 138 139 |
# File 'lib/groonga/client/response/base.rb', line 137 def raw @raw end |
Class Method Details
.parse(command, raw_response) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/groonga/client/response/base.rb', line 52 def parse(command, raw_response) case command.output_type when :json header, body = JSON.parse(raw_response) when :xml header, body = parse_xml(raw_response) else header = nil body = raw_response end if header.nil? or header[0].zero? response = new(command, header, body) else response = Error.new(command, header, body) end response.raw = raw_response response end |
Instance Method Details
#elapsed_time ⇒ Time
Returns The elapsed time of the request.
160 161 162 |
# File 'lib/groonga/client/response/base.rb', line 160 def elapsed_time (header || [0, 0, 0.0])[2] end |
#start_time ⇒ Time
Returns The time of the request is accepted.
154 155 156 |
# File 'lib/groonga/client/response/base.rb', line 154 def start_time Time.at((header || [0, 0])[1]) end |
#status_code ⇒ Integer
Returns The status code of the response.
148 149 150 |
# File 'lib/groonga/client/response/base.rb', line 148 def status_code (header || [0])[0] end |
#success? ⇒ Boolean
Returns true
if the request is processed successfully,
false
otherwise.
167 168 169 |
# File 'lib/groonga/client/response/base.rb', line 167 def success? status_code.zero? end |