class Commande::Result

Constants

METHODS

Concrete methods

@api private

@see Commande::Result#respond_to_missing?

Public Class Methods

new(payload = {}) click to toggle source

Initialize a new result

@param payload [Hash] a payload to carry on

@return [Commande::Result]

@api private

# File lib/commande.rb, line 29
def initialize(payload = {})
  @payload = payload
  @errors  = []
  @logs = []
  @success = true
end

Public Instance Methods

add_error(*errors) click to toggle source

@api private

# File lib/commande.rb, line 68
def add_error(*errors)
  @errors << errors
  @errors.flatten!
  nil
end
add_log(*logs) click to toggle source

@api private

# File lib/commande.rb, line 98
def add_log(*logs)
  @logs << logs
  @logs.flatten!
  nil
end
class() click to toggle source

Return the class for debugging purposes.

@see ruby-doc.org/core/Object.html#method-i-class

# File lib/commande.rb, line 121
def class
  (class << self; self; end).superclass
end
error() click to toggle source

Returns the first errors collected during an operation

@return [nil,String] the error, if present

@see Commande::Result#errors @see Commande#call @see Commande#error @see Commande#error!

# File lib/commande.rb, line 83
def error
  errors.first
end
errors() click to toggle source

Returns all the errors collected during an operation

@return [Array] the errors

@see Commande::Result#error @see Commande#call @see Commande#error @see Commande#error!

# File lib/commande.rb, line 63
def errors
  @errors.dup
end
fail!() click to toggle source

Force the status to be a failure

# File lib/commande.rb, line 51
def fail!
  @success = false
end
failure?() click to toggle source

Check if the current status is not successful

@return [TrueClass,FalseClass] the result of the check

# File lib/commande.rb, line 46
def failure?
  !successful?
end
inspect() click to toggle source

Bare minimum inspect for debugging purposes.

@return [String] the inspect string

@see ruby-doc.org/core/Object.html#method-i-inspect

# File lib/commande.rb, line 132
def inspect
  "#<#{self.class}:#{::Kernel.format('0x0000%<id>x', id: (__id__ << 1))}#{__inspect}>"
end
logs() click to toggle source

Returns all the logs collected during an operation

@return [Array] the errors

@see Commande::Result#log @see Commande#call

# File lib/commande.rb, line 93
def logs
  @logs.dup
end
object_id() click to toggle source

Alias for __id__

@return [Fixnum] the object id

@see ruby-doc.org/core/Object.html#method-i-object_id

# File lib/commande.rb, line 141
def object_id
  __id__
end
payload() click to toggle source
# File lib/commande.rb, line 114
def payload
  @payload.dup
end
prepare!(payload) click to toggle source

Prepare the result before to be returned

@param payload [Hash] an updated payload

@api private

# File lib/commande.rb, line 109
def prepare!(payload)
  @payload.merge!(payload)
  self
end
respond_to?(method_name, include_all = false) click to toggle source

Returns true if responds to the given method.

@return [TrueClass,FalseClass] the result of the check

@see ruby-doc.org/core-2.2.1/Object.html#method-i-respond_to-3F

# File lib/commande.rb, line 150
def respond_to?(method_name, include_all = false)
  respond_to_missing?(method_name, include_all)
end
successful?() click to toggle source

Check if the current status is successful

@return [TrueClass,FalseClass] the result of the check

# File lib/commande.rb, line 39
def successful?
  @success && errors.empty?
end

Protected Instance Methods

__inspect() click to toggle source

@api private

# File lib/commande.rb, line 168
def __inspect
  " @success=#{@success} @payload=#{@payload.inspect}"
end
method_missing(method_name, *) click to toggle source

@api private

Calls superclass method
# File lib/commande.rb, line 157
def method_missing(method_name, *)
  @payload.fetch(method_name) { super }
end
respond_to_missing?(method_name, _include_all) click to toggle source

@api private

# File lib/commande.rb, line 162
def respond_to_missing?(method_name, _include_all)
  method_name = method_name.to_sym
  METHODS[method_name] || @payload.key?(method_name)
end