Class: Crossbeam::Result

Inherits:
Struct
  • Object
show all
Defined in:
lib/crossbeam/result.rb

Overview

Used as a data container to hold a service calls results, errors, etc. class Result < Struct.new(:called, :errors, :failure, :results)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(called: false, errors: nil, failure: false, results: nil) ⇒ Result

Used to initialize a service calls results, errors, and stats

Parameters:

  • called (Boolean) (defaults to: false)
  • errors (Hash) (defaults to: nil)
  • failure (Boolean) (defaults to: false)
  • results (Object) (defaults to: nil)


22
23
24
25
26
27
28
29
# File 'lib/crossbeam/result.rb', line 22

def initialize(called: false, errors: nil, failure: false, results: nil)
  super(called, errors, failure, results)

  self.called = called
  self.errors = Crossbeam::Errors.new
  self.failure = failure
  self.results = nil
end

Instance Attribute Details

#calledObject

Returns the value of attribute called

Returns:

  • (Object)

    the current value of called



11
12
13
# File 'lib/crossbeam/result.rb', line 11

def called
  @called
end

#errorsObject

Returns the value of attribute errors

Returns:

  • (Object)

    the current value of errors



11
12
13
# File 'lib/crossbeam/result.rb', line 11

def errors
  @errors
end

#failureObject

Returns the value of attribute failure

Returns:

  • (Object)

    the current value of failure



11
12
13
# File 'lib/crossbeam/result.rb', line 11

def failure
  @failure
end

#resultsObject

Returns the value of attribute results

Returns:

  • (Object)

    the current value of results



11
12
13
# File 'lib/crossbeam/result.rb', line 11

def results
  @results
end

Instance Method Details

#called?Boolean

The serivce can’t officially be a failure/pass if it hasn’t been “called”

Returns:

  • (Boolean)


34
35
36
# File 'lib/crossbeam/result.rb', line 34

def called?
  called || false
end

#errors?Boolean

Determine if the service call has any errors

Returns:

  • (Boolean)


41
42
43
# File 'lib/crossbeam/result.rb', line 41

def errors?
  (errors.is_a?(Hash) && errors.any?) || false
end

#failure?Boolean

Determine if the service call has failed to uccessfully complete

Returns:

  • (Boolean)


48
49
50
# File 'lib/crossbeam/result.rb', line 48

def failure?
  called? && issues?
end

#success?Boolean

Determine if the service call has successfully ran

Returns:

  • (Boolean)


55
56
57
# File 'lib/crossbeam/result.rb', line 55

def success?
  called? && !issues?
end