Class: AGIState
- Inherits:
-
Object
- Object
- AGIState
- Defined in:
- lib/AGIState.rb
Overview
AGIState is meant to be subclassed to implement any state that needs to persist throughout an AGI session within the framework. By default, it can be sed to increase and reset failiure counters, and have an AGIStateException thrown when conditions are met.
Constant Summary collapse
- @@failure_threshold =
3
Instance Attribute Summary collapse
-
#failure_threshold ⇒ Object
readonly
Returns the value of attribute failure_threshold.
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
Class Method Summary collapse
Instance Method Summary collapse
- #failure_inc ⇒ Object
- #failure_reset ⇒ Object
-
#initialize(conf = {}) ⇒ AGIState
constructor
A new instance of AGIState.
Constructor Details
#initialize(conf = {}) ⇒ AGIState
Returns a new instance of AGIState.
41 42 43 44 45 |
# File 'lib/AGIState.rb', line 41 def initialize(conf={}) @failures = 0 @failure_threshold = conf[:threshold] || @@failure_threshold @failure_threshold = conf[:failure_threshold] || @failure_threshold end |
Instance Attribute Details
#failure_threshold ⇒ Object (readonly)
Returns the value of attribute failure_threshold.
40 41 42 |
# File 'lib/AGIState.rb', line 40 def failure_threshold @failure_threshold end |
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
39 40 41 |
# File 'lib/AGIState.rb', line 39 def failures @failures end |
Class Method Details
.failure_threshold=(threshold) ⇒ Object
46 47 48 |
# File 'lib/AGIState.rb', line 46 def self.failure_threshold=(threshold) @@failure_threshold = threshold end |
Instance Method Details
#failure_inc ⇒ Object
49 50 51 52 53 54 |
# File 'lib/AGIState.rb', line 49 def failure_inc @failures += 1 if @failures >= @failure_threshold then raise AGIStateFailure.new("Too many failures ( #{@failures} >= #{@failure_threshold})" ) end end |
#failure_reset ⇒ Object
55 56 57 58 59 60 |
# File 'lib/AGIState.rb', line 55 def failure_reset @failures = 0 if @failures >= @failure_threshold then raise AGIStateFailure.new("Too many failures ( #{@failures} >= #{@failure_threshold})") end end |