Class: Leap::Committee
- Inherits:
-
Object
- Object
- Leap::Committee
- Defined in:
- lib/leap/committee.rb
Overview
One of the basic building blocks of a Leap decision.
Committees represent computable attributes of a subject instance and facilitate multiple means of computing these attributes. In some cases, you will define committees that match the names of attributes that can be explicitly set on a subject; in this case, the committees are only useful when a particular instance does not have this attribute set. In other cases, committees are part of internal logic within the Leap decision, providing intermediate results in pursuit of the decision’s ultimate goal.
As a Leap decision is made, it approaches each committee in turn, providing it with its current knowledge of the subject. The committee accepts this information, determines an appropriate methodology, and returns additional information about the subject. This newly-augmented knowledge about the subject is then passed to the next committee for further augmentation, and so forth.
Committees are composed of one or more quorums (Leap::Quorum
objects) that encapsulate specific methodologies for drawing the committee’s conclusion. This composition is defined within the Leap::Decision#committee
block using the Leap::Committee#quorum
DSL.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the committee, traditionally formulated to represent a computable attribute of the subject.
-
#options ⇒ Object
readonly
An options hash.
-
#quorums ⇒ Object
readonly
The array of quorums defined within the committee.
Instance Method Summary collapse
-
#default(options = {}, &blk) ⇒ Object
Convenience method for defining a quorum named “default” with no needs, wants, or compliances.
-
#initialize(name, options) ⇒ Committee
constructor
Creates a new
Leap::Committee
with the given name. -
#quorum(name, options = {}) { ... } ⇒ Object
Defines a quorum within this committee.
-
#report(characteristics, considerations, options = {}) ⇒ Object
Instructs the committee to draw its conclusion.
Constructor Details
#initialize(name, options) ⇒ Committee
Creates a new Leap::Committee
with the given name.
Generally you don’t create these objects directly; Leap::Decision#committee
does that for you.
31 32 33 34 35 |
# File 'lib/leap/committee.rb', line 31 def initialize(name, ) @name = name @options = @quorums = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
The name of the committee, traditionally formulated to represent a computable attribute of the subject.
16 17 18 |
# File 'lib/leap/committee.rb', line 16 def name @name end |
#options ⇒ Object (readonly)
An options hash
22 23 24 |
# File 'lib/leap/committee.rb', line 22 def @options end |
#quorums ⇒ Object (readonly)
The array of quorums defined within the committee.
19 20 21 |
# File 'lib/leap/committee.rb', line 19 def quorums @quorums end |
Instance Method Details
#default(options = {}, &blk) ⇒ Object
Convenience method for defining a quorum named “default” with no needs, wants, or compliances.
76 77 78 |
# File 'lib/leap/committee.rb', line 76 def default( = {}, &blk) quorum 'default', , &blk end |
#quorum(name, options = {}) { ... } ⇒ Object
Defines a quorum within this committee.
A quorum encapsulate a specific methodology for drawing the committe’s conclusion.
71 72 73 |
# File 'lib/leap/committee.rb', line 71 def quorum(name, = {}, &blk) @quorums << ::Leap::Quorum.new(name, , blk) end |
#report(characteristics, considerations, options = {}) ⇒ Object
Instructs the committee to draw its conclusion.
Steps through each quorum defined within the committee in search of one that can be called with the provided characteristics and is compliant with the requested protocols. Upon finding such a quorum, it is called. If a conclusion is returned, it becomes the committee’s conclusion; if not, the quorum-seeking process continues.
Generally you will not call this method directly; Leap::Decision#make
requests reports at the appropriate time.
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/leap/committee.rb', line 48 def report(characteristics, considerations, = {}) Leap.log.committee "Convening committee", name quorums.each do |quorum| Leap.log.quorum "Assessing quorum", quorum.name next unless quorum.satisfied_by? characteristics and quorum.complies_with? [:comply] Leap.log.quorum "Acknowledging quorum", quorum.name if conclusion = quorum.acknowledge(characteristics.slice(*quorum.characteristics), considerations.dup) Leap.log.quorum "Success", quorum.name return ::Leap::Report.new(self, quorum, conclusion) end end nil end |