Class: Fluent::Counter::Server::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/counter/server.rb

Instance Method Summary collapse

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_hashObject



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