class Opera::Operation::Result

Attributes

errors[R]
exceptions[R]
executions[R]
information[R]
output[RW]
to_h[RW]

Public Class Methods

new(output: nil, errors: {}) click to toggle source
# File lib/opera/operation/result.rb, line 15
def initialize(output: nil, errors: {})
  @errors = errors
  @exceptions = {}
  @information = {}
  @executions = []
  @output = output
end

Public Instance Methods

add_error(field, message) click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/opera/operation/result.rb, line 32
def add_error(field, message)
  @errors[field] ||= []
  if message.is_a?(Hash)
    if @errors[field].first&.is_a?(Hash)
      @errors[field].first.merge!(message)
    else
      @errors[field].push(message)
    end
  else
    @errors[field].concat(Array(message))
  end
  @errors[field].uniq!
end
add_errors(errors) click to toggle source

rubocop:enable Metrics/MethodLength

# File lib/opera/operation/result.rb, line 47
def add_errors(errors)
  errors.to_h.each_pair do |key, value|
    add_error(key, value)
  end
end
add_exception(method, message, classname: nil) click to toggle source
# File lib/opera/operation/result.rb, line 53
def add_exception(method, message, classname: nil)
  key = [classname, Array(method).first].compact.join('#')
  @exceptions[key] ||= []
  @exceptions[key].push(message)
end
add_exceptions(exceptions) click to toggle source
# File lib/opera/operation/result.rb, line 59
def add_exceptions(exceptions)
  exceptions.each_pair do |key, value|
    add_exception(key, value)
  end
end
add_execution(step) click to toggle source
# File lib/opera/operation/result.rb, line 69
def add_execution(step)
  @executions << step
end
add_information(hash) click to toggle source
# File lib/opera/operation/result.rb, line 65
def add_information(hash)
  @information.merge!(hash)
end
failure?() click to toggle source
# File lib/opera/operation/result.rb, line 23
def failure?
  errors.any? || exceptions.any?
end
success?() click to toggle source
# File lib/opera/operation/result.rb, line 27
def success?
  !failure?
end