Class: ActionAgent::AgentVersion

Inherits:
ApplicationRecord show all
Defined in:
app/models/action_agent/agent_version.rb

Instance Method Summary collapse

Methods inherited from ApplicationRecord

for_owner, owner_association

Instance Method Details

#diff(other_version) ⇒ Object

Compare two versions



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/action_agent/agent_version.rb', line 15

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)


44
45
46
# File 'app/models/action_agent/agent_version.rb', line 44

def initial?
  version_number == 1
end

#latest?Boolean

Check if this is the latest version

Returns:

  • (Boolean)


39
40
41
# File 'app/models/action_agent/agent_version.rb', line 39

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

#next_versionObject

Get next version



34
35
36
# File 'app/models/action_agent/agent_version.rb', line 34

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

#previousObject

Get previous version



29
30
31
# File 'app/models/action_agent/agent_version.rb', line 29

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