Class: Aidp::AutoUpdate::UpdatePolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/aidp/auto_update/update_policy.rb

Overview

Value object representing auto-update configuration policy

Constant Summary collapse

VALID_POLICIES =
%w[off exact patch minor major].freeze
VALID_SUPERVISORS =
%w[none supervisord s6 runit].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enabled: false, policy: "off", allow_prerelease: false, check_interval_seconds: 3600, supervisor: "none", max_consecutive_failures: 3) ⇒ UpdatePolicy

Returns a new instance of UpdatePolicy.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/aidp/auto_update/update_policy.rb', line 13

def initialize(
  enabled: false,
  policy: "off",
  allow_prerelease: false,
  check_interval_seconds: 3600,
  supervisor: "none",
  max_consecutive_failures: 3
)
  @enabled = enabled
  @policy = validate_policy(policy)
  @allow_prerelease = allow_prerelease
  @check_interval_seconds = validate_interval(check_interval_seconds)
  @supervisor = validate_supervisor(supervisor)
  @max_consecutive_failures = validate_max_failures(max_consecutive_failures)
end

Instance Attribute Details

#allow_prereleaseObject (readonly)

Returns the value of attribute allow_prerelease.



7
8
9
# File 'lib/aidp/auto_update/update_policy.rb', line 7

def allow_prerelease
  @allow_prerelease
end

#check_interval_secondsObject (readonly)

Returns the value of attribute check_interval_seconds.



7
8
9
# File 'lib/aidp/auto_update/update_policy.rb', line 7

def check_interval_seconds
  @check_interval_seconds
end

#enabledObject (readonly)

Returns the value of attribute enabled.



7
8
9
# File 'lib/aidp/auto_update/update_policy.rb', line 7

def enabled
  @enabled
end

#max_consecutive_failuresObject (readonly)

Returns the value of attribute max_consecutive_failures.



7
8
9
# File 'lib/aidp/auto_update/update_policy.rb', line 7

def max_consecutive_failures
  @max_consecutive_failures
end

#policyObject (readonly)

Returns the value of attribute policy.



7
8
9
# File 'lib/aidp/auto_update/update_policy.rb', line 7

def policy
  @policy
end

#supervisorObject (readonly)

Returns the value of attribute supervisor.



7
8
9
# File 'lib/aidp/auto_update/update_policy.rb', line 7

def supervisor
  @supervisor
end

Class Method Details

.disabledUpdatePolicy

Create a disabled policy

Returns:



47
48
49
# File 'lib/aidp/auto_update/update_policy.rb', line 47

def self.disabled
  new(enabled: false, policy: "off")
end

.from_config(config) ⇒ UpdatePolicy

Create from configuration hash

Parameters:

  • config (Hash)

    Configuration hash from aidp.yml

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/aidp/auto_update/update_policy.rb', line 32

def self.from_config(config)
  return disabled unless config

  new(
    enabled: config[:enabled] || config["enabled"] || false,
    policy: config[:policy] || config["policy"] || "off",
    allow_prerelease: config[:allow_prerelease] || config["allow_prerelease"] || false,
    check_interval_seconds: config[:check_interval_seconds] || config["check_interval_seconds"] || 3600,
    supervisor: config[:supervisor] || config["supervisor"] || "none",
    max_consecutive_failures: config[:max_consecutive_failures] || config["max_consecutive_failures"] || 3
  )
end

Instance Method Details

#disabled?Boolean

Check if updates are completely disabled

Returns:

  • (Boolean)


53
54
55
# File 'lib/aidp/auto_update/update_policy.rb', line 53

def disabled?
  !@enabled || @policy == "off"
end

#supervised?Boolean

Check if a supervisor is configured

Returns:

  • (Boolean)


59
60
61
# File 'lib/aidp/auto_update/update_policy.rb', line 59

def supervised?
  @supervisor != "none"
end

#to_hHash

Convert to hash for serialization

Returns:

  • (Hash)


65
66
67
68
69
70
71
72
73
74
# File 'lib/aidp/auto_update/update_policy.rb', line 65

def to_h
  {
    enabled: @enabled,
    policy: @policy,
    allow_prerelease: @allow_prerelease,
    check_interval_seconds: @check_interval_seconds,
    supervisor: @supervisor,
    max_consecutive_failures: @max_consecutive_failures
  }
end