class Voom::Commands::Response

Constants

FAILURE
SUCCESS

Attributes

data[R]
messages[R]
status[R]

Public Class Methods

new(data: [], status: SUCCESS, messages: {}) click to toggle source
# File lib/voom/commands/response.rb, line 10
def initialize(data: [],
               status: SUCCESS,
               messages: {})
  @data = data
  @status = status
  @messages = Messages.new(messages)
end

Public Instance Methods

<<(output) click to toggle source
# File lib/voom/commands/response.rb, line 29
def <<(output)
  @data << output
end
[](key) click to toggle source

If your data either is a hash or is an array containing one hash This helper allows you to treat the result object as a hash returns nil if there is more than one element in the data Or if the data is empty

# File lib/voom/commands/response.rb, line 22
def [](key)
  return data[key] if data.respond_to?(:key?) #quacks like a hash
  return data.send(key.to_sym) if data.respond_to?(key.to_sym) #behaves like a model/entity
  return nil if data.empty? or data.size > 1
  data.first[key] if data.first.respond_to?(:key?)
end
errors() click to toggle source
# File lib/voom/commands/response.rb, line 51
def errors
  @messages.errors
end
fail?()
Alias for: failed?
failed?() click to toggle source
# File lib/voom/commands/response.rb, line 39
def failed?
  !succeeded?
end
Also aliased as: fail?
succeeded?() click to toggle source
# File lib/voom/commands/response.rb, line 33
def succeeded?
  @status == SUCCESS
end
Also aliased as: success?
success?()
Alias for: succeeded?
to_h() click to toggle source
# File lib/voom/commands/response.rb, line 45
def to_h
  {data: data,
   status: status,
   message: messages.to_h}
end
warnings() click to toggle source
# File lib/voom/commands/response.rb, line 55
def warnings
  @messages.warnings
end