Module: Leap::Subject
- Defined in:
- lib/leap/subject.rb
Overview
In Leap lingo, Subject refers to the host class, instances of which we’re trying to arrive at conclusions about.
It is within Subjects that we establish decision-making strategies using #decide
Instance Attribute Summary collapse
-
#decisions ⇒ Object
readonly
Accumulates
Leap::Decision
objects, having been defined with#decide
.
Class Method Summary collapse
-
.extended(base) ⇒ Object
Establishes the
@decisions
class instance variable for accumulating Leap decisions, along with an accessor for their deliberations.
Instance Method Summary collapse
-
#decide(goal, options = {}, &blk) ⇒ Object
Defines a new
Leap::Decision
on the subject, using a DSL within its block.
Instance Attribute Details
#decisions ⇒ Object (readonly)
Accumulates Leap::Decision
objects, having been defined with #decide
.
22 23 24 |
# File 'lib/leap/subject.rb', line 22 def decisions @decisions end |
Class Method Details
.extended(base) ⇒ Object
Establishes the @decisions
class instance variable for accumulating Leap decisions, along with an accessor for their deliberations. Also injects Leap::ImplicitAttributes
, which provides a low-budget attribute curation method.
13 14 15 16 17 18 |
# File 'lib/leap/subject.rb', line 13 def self.extended(base) base.instance_variable_set :@decisions, {} base.send :include, ::Leap::ImplicitAttributes base.send :include, ::Leap::DeliberationsAccessor base.send :include, ::Leap::GoalMethodsDocumentation end |
Instance Method Details
#decide(goal, options = {}, &blk) ⇒ Object
Defines a new Leap::Decision
on the subject, using a DSL within its block.
The DSL within the block is primarily composed of Leap::Decision#committee
. Using #decide
will define a new method on instances of the subject class, named after the decision’s goal
, that computes the decision through a process called deliberation (see Leap::GoalMethodsDocumentation
).
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/leap/subject.rb', line 49 def decide(goal, = {}, &blk) decisions[goal] = ::Leap::Decision.new goal, decisions[goal].instance_eval(&blk) define_method goal do |*considerations| decision = self.class.decisions[goal] = considerations. @deliberations ||= {} Leap.instrument.decision goal do characteristics = send(decision.signature_method) @deliberations[goal] = decision.make(characteristics, , *considerations) end if decision.mastered? and @deliberations[goal][goal].nil? raise ::Leap::NoSolutionError, :goal => goal, :deliberation => @deliberations[goal] elsif decision.mastered? Leap.log.decision "Success", goal @deliberations[goal][goal] elsif [:comply].is_a? Hash [:comply].each do |protocol, committees| [committees].flatten.each do |committee| @deliberations[goal].compliance(committee).include?(protocol) or raise ::Leap::NoSolutionError, :goal => committee, :deliberation => @deliberations[goal] end end Leap.log.decision "Success", goal @deliberations[goal] else Leap.log.decision "Success", goal @deliberations[goal] end end end |