Class: Fluent::Counter::Server::Response
- Inherits:
-
Object
- Object
- Fluent::Counter::Server::Response
- Defined in:
- lib/fluent/counter/server.rb
Instance Method Summary collapse
-
#initialize(errors = [], data = []) ⇒ Response
constructor
A new instance of Response.
- #push_data(data) ⇒ Object
- #push_error(error) ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(errors = [], data = []) ⇒ Response
Returns a new instance of Response.
234 235 236 237 |
# File 'lib/fluent/counter/server.rb', line 234 def initialize(errors = [], data = []) @errors = errors @data = data end |
Instance Method Details
#push_data(data) ⇒ Object
243 244 245 |
# File 'lib/fluent/counter/server.rb', line 243 def push_data(data) @data << data end |
#push_error(error) ⇒ Object
239 240 241 |
# File 'lib/fluent/counter/server.rb', line 239 def push_error(error) @errors << error end |
#to_hash ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/fluent/counter/server.rb', line 247 def to_hash if @errors.empty? { 'data' => @data } else errors = @errors.map do |e| error = e.respond_to?(:to_hash) ? e : InternalServerError.new(e.to_s) error.to_hash end { 'data' => @data, 'errors' => errors } end end |