Class: Legion::Extensions::Agentic::Self::Architecture::Helpers::Subsystem
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Self::Architecture::Helpers::Subsystem
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb
Constant Summary
Constants included from Constants
Constants::BOTTLENECK_THRESHOLD, Constants::CONNECTION_TYPES, Constants::DEFAULT_HEALTH, Constants::HEALTH_BOOST, Constants::HEALTH_DECAY, Constants::HEALTH_LABELS, Constants::MAX_CONNECTIONS, Constants::MAX_HISTORY, Constants::MAX_SUBSYSTEMS, Constants::STATUS_LEVELS, Constants::SUBSYSTEM_TYPES
Instance Attribute Summary collapse
-
#activation_count ⇒ Object
readonly
Returns the value of attribute activation_count.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#health ⇒ Object
Returns the value of attribute health.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_activated_at ⇒ Object
readonly
Returns the value of attribute last_activated_at.
-
#load ⇒ Object
Returns the value of attribute load.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#status ⇒ Object
Returns the value of attribute status.
-
#subsystem_type ⇒ Object
readonly
Returns the value of attribute subsystem_type.
Instance Method Summary collapse
- #activate! ⇒ Object
- #bottlenecked? ⇒ Boolean
- #degrade!(amount = Constants::HEALTH_DECAY) ⇒ Object
- #health_label ⇒ Object
-
#initialize(name:, subsystem_type:, health: Constants::DEFAULT_HEALTH) ⇒ Subsystem
constructor
A new instance of Subsystem.
- #recover!(amount = Constants::HEALTH_BOOST) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(name:, subsystem_type:, health: Constants::DEFAULT_HEALTH) ⇒ Subsystem
Returns a new instance of Subsystem.
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 17 def initialize(name:, subsystem_type:, health: Constants::DEFAULT_HEALTH) @id = SecureRandom.uuid @name = name.to_sym @subsystem_type = subsystem_type.to_sym @health = health.clamp(0.0, 1.0) @status = :active @load = 0.0 @activation_count = 0 @last_activated_at = nil @created_at = Time.now.utc end |
Instance Attribute Details
#activation_count ⇒ Object (readonly)
Returns the value of attribute activation_count.
14 15 16 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 14 def activation_count @activation_count end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 14 def created_at @created_at end |
#health ⇒ Object
Returns the value of attribute health.
15 16 17 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 15 def health @health end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
14 15 16 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 14 def id @id end |
#last_activated_at ⇒ Object (readonly)
Returns the value of attribute last_activated_at.
14 15 16 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 14 def last_activated_at @last_activated_at end |
#load ⇒ Object
Returns the value of attribute load.
15 16 17 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 15 def load @load end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 14 def name @name end |
#status ⇒ Object
Returns the value of attribute status.
15 16 17 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 15 def status @status end |
#subsystem_type ⇒ Object (readonly)
Returns the value of attribute subsystem_type.
14 15 16 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 14 def subsystem_type @subsystem_type end |
Instance Method Details
#activate! ⇒ Object
29 30 31 32 33 34 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 29 def activate! @activation_count += 1 @last_activated_at = Time.now.utc @health = (@health + Constants::HEALTH_BOOST).clamp(0.0, 1.0) self end |
#bottlenecked? ⇒ Boolean
48 49 50 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 48 def bottlenecked? @load > Constants::BOTTLENECK_THRESHOLD && @health < 0.5 end |
#degrade!(amount = Constants::HEALTH_DECAY) ⇒ Object
36 37 38 39 40 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 36 def degrade!(amount = Constants::HEALTH_DECAY) @health = (@health - amount).clamp(0.0, 1.0) @status = :degraded if @health < 0.4 self end |
#health_label ⇒ Object
52 53 54 55 56 57 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 52 def health_label Constants::HEALTH_LABELS.each do |range, label| return label if range.cover?(@health) end :critical end |
#recover!(amount = Constants::HEALTH_BOOST) ⇒ Object
42 43 44 45 46 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 42 def recover!(amount = Constants::HEALTH_BOOST) @health = (@health + amount).clamp(0.0, 1.0) @status = :active if @health >= 0.4 self end |
#to_h ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/legion/extensions/agentic/self/architecture/helpers/subsystem.rb', line 59 def to_h { id: @id, name: @name, subsystem_type: @subsystem_type, health: @health, health_label: health_label, status: @status, load: @load, activation_count: @activation_count, last_activated_at: @last_activated_at, created_at: @created_at, bottlenecked: bottlenecked? } end |