Class: Legion::Extensions::Agentic::Self::Architecture::Helpers::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/self/architecture/helpers/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_id:, target_id:, connection_type: :informational, weight: 0.5) ⇒ Connection

Returns a new instance of Connection.



15
16
17
18
19
20
21
22
23
# File 'lib/legion/extensions/agentic/self/architecture/helpers/connection.rb', line 15

def initialize(source_id:, target_id:, connection_type: :informational, weight: 0.5)
  @id              = SecureRandom.uuid
  @source_id       = source_id
  @target_id       = target_id
  @connection_type = connection_type.to_sym
  @weight          = weight.clamp(0.0, 1.0)
  @active          = true
  @created_at      = Time.now.utc
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



13
14
15
# File 'lib/legion/extensions/agentic/self/architecture/helpers/connection.rb', line 13

def active
  @active
end

#connection_typeObject (readonly)

Returns the value of attribute connection_type.



12
13
14
# File 'lib/legion/extensions/agentic/self/architecture/helpers/connection.rb', line 12

def connection_type
  @connection_type
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/self/architecture/helpers/connection.rb', line 12

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/self/architecture/helpers/connection.rb', line 12

def id
  @id
end

#source_idObject (readonly)

Returns the value of attribute source_id.



12
13
14
# File 'lib/legion/extensions/agentic/self/architecture/helpers/connection.rb', line 12

def source_id
  @source_id
end

#target_idObject (readonly)

Returns the value of attribute target_id.



12
13
14
# File 'lib/legion/extensions/agentic/self/architecture/helpers/connection.rb', line 12

def target_id
  @target_id
end

#weightObject

Returns the value of attribute weight.



13
14
15
# File 'lib/legion/extensions/agentic/self/architecture/helpers/connection.rb', line 13

def weight
  @weight
end

Instance Method Details

#strengthen!(amount = 0.05) ⇒ Object



25
26
27
28
# File 'lib/legion/extensions/agentic/self/architecture/helpers/connection.rb', line 25

def strengthen!(amount = 0.05)
  @weight = (@weight + amount).clamp(0.0, 1.0)
  self
end

#to_hObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/legion/extensions/agentic/self/architecture/helpers/connection.rb', line 40

def to_h
  {
    id:              @id,
    source_id:       @source_id,
    target_id:       @target_id,
    connection_type: @connection_type,
    weight:          @weight,
    active:          @active,
    created_at:      @created_at
  }
end

#toggle!Object



35
36
37
38
# File 'lib/legion/extensions/agentic/self/architecture/helpers/connection.rb', line 35

def toggle!
  @active = !@active
  self
end

#weaken!(amount = 0.05) ⇒ Object



30
31
32
33
# File 'lib/legion/extensions/agentic/self/architecture/helpers/connection.rb', line 30

def weaken!(amount = 0.05)
  @weight = (@weight - amount).clamp(0.0, 1.0)
  self
end