Class: CircuitBreaker::Rules::RuleResult

Inherits:
Object
  • Object
show all
Defined in:
lib/circuit_breaker/rules.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(valid, errors = []) ⇒ RuleResult

Returns a new instance of RuleResult.



11
12
13
14
# File 'lib/circuit_breaker/rules.rb', line 11

def initialize(valid, errors = [])
  @valid = valid
  @errors = Array(errors)
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



9
10
11
# File 'lib/circuit_breaker/rules.rb', line 9

def errors
  @errors
end

#validObject (readonly)

Returns the value of attribute valid.



9
10
11
# File 'lib/circuit_breaker/rules.rb', line 9

def valid
  @valid
end

Instance Method Details

#&(other) ⇒ Object



24
25
26
27
28
29
# File 'lib/circuit_breaker/rules.rb', line 24

def &(other)
  RuleResult.new(
    valid? && other.valid?,
    errors + other.errors
  )
end

#to_sObject



20
21
22
# File 'lib/circuit_breaker/rules.rb', line 20

def to_s
  valid? ? "valid" : "invalid: #{errors.join(', ')}"
end

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/circuit_breaker/rules.rb', line 16

def valid?
  @valid
end

#|(other) ⇒ Object



31
32
33
34
35
36
# File 'lib/circuit_breaker/rules.rb', line 31

def |(other)
  RuleResult.new(
    valid? || other.valid?,
    valid? || other.valid? ? [] : errors + other.errors
  )
end