Class: ActiveAgent::Dashboard::AgentVersion

Inherits:
ApplicationRecord show all
Defined in:
lib/active_agent/dashboard/app/models/active_agent/dashboard/agent_version.rb

Overview

Tracks version history for agent configurations.

Each time an agent’s configuration changes, a new version is created with a snapshot of the configuration at that point in time.

Examples:

Comparing versions

v1 = agent.agent_versions.find_by(version_number: 1)
v2 = agent.agent_versions.find_by(version_number: 2)
changes = v2.diff(v1)

Instance Method Summary collapse

Methods inherited from ApplicationRecord

for_owner, owner_association, table_name

Instance Method Details

#diff(other_version) ⇒ Object

Compare two versions



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/active_agent/dashboard/app/models/active_agent/dashboard/agent_version.rb', line 26

def diff(other_version)
  return {} unless other_version

  changes = {}
  configuration_snapshot.each do |key, value|
    other_value = other_version.configuration_snapshot[key]
    if value != other_value
      changes[key] = { from: other_value, to: value }
    end
  end
  changes
end

#initial?Boolean

Check if this is the initial version

Returns:

  • (Boolean)


55
56
57
# File 'lib/active_agent/dashboard/app/models/active_agent/dashboard/agent_version.rb', line 55

def initial?
  version_number == 1
end

#latest?Boolean

Check if this is the latest version

Returns:

  • (Boolean)


50
51
52
# File 'lib/active_agent/dashboard/app/models/active_agent/dashboard/agent_version.rb', line 50

def latest?
  agent.latest_version&.id == id
end

#next_versionObject

Get next version



45
46
47
# File 'lib/active_agent/dashboard/app/models/active_agent/dashboard/agent_version.rb', line 45

def next_version
  agent.agent_versions.where("version_number > ?", version_number).order(version_number: :asc).first
end

#previousObject

Get previous version



40
41
42
# File 'lib/active_agent/dashboard/app/models/active_agent/dashboard/agent_version.rb', line 40

def previous
  agent.agent_versions.where("version_number < ?", version_number).order(version_number: :desc).first
end