Class: Aidp::AutoUpdate::UpdateCheck

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

Overview

Value object representing the result of an update check

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_version:, available_version:, update_available:, update_allowed:, policy_reason: nil, checked_at: Time.now, error: nil) ⇒ UpdateCheck

Returns a new instance of UpdateCheck.



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

def initialize(
  current_version:,
  available_version:,
  update_available:,
  update_allowed:,
  policy_reason: nil,
  checked_at: Time.now,
  error: nil
)
  @current_version = current_version
  @available_version = available_version
  @update_available = update_available
  @update_allowed = update_allowed
  @policy_reason = policy_reason
  @checked_at = checked_at
  @error = error
end

Instance Attribute Details

#available_versionObject (readonly)

Returns the value of attribute available_version.



9
10
11
# File 'lib/aidp/auto_update/update_check.rb', line 9

def available_version
  @available_version
end

#checked_atObject (readonly)

Returns the value of attribute checked_at.



9
10
11
# File 'lib/aidp/auto_update/update_check.rb', line 9

def checked_at
  @checked_at
end

#current_versionObject (readonly)

Returns the value of attribute current_version.



9
10
11
# File 'lib/aidp/auto_update/update_check.rb', line 9

def current_version
  @current_version
end

#errorObject (readonly)

Returns the value of attribute error.



9
10
11
# File 'lib/aidp/auto_update/update_check.rb', line 9

def error
  @error
end

#policy_reasonObject (readonly)

Returns the value of attribute policy_reason.



9
10
11
# File 'lib/aidp/auto_update/update_check.rb', line 9

def policy_reason
  @policy_reason
end

#update_allowedObject (readonly)

Returns the value of attribute update_allowed.



9
10
11
# File 'lib/aidp/auto_update/update_check.rb', line 9

def update_allowed
  @update_allowed
end

#update_availableObject (readonly)

Returns the value of attribute update_available.



9
10
11
# File 'lib/aidp/auto_update/update_check.rb', line 9

def update_available
  @update_available
end

Class Method Details

.failed(error_message, current_version: Aidp::VERSION) ⇒ UpdateCheck

Create a failed update check

Parameters:

  • error_message (String)

    Error message

  • current_version (String) (defaults to: Aidp::VERSION)

    Current version

Returns:



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

def self.failed(error_message, current_version: Aidp::VERSION)
  new(
    current_version: current_version,
    available_version: current_version,
    update_available: false,
    update_allowed: false,
    policy_reason: "Update check failed",
    error: error_message
  )
end

.from_h(hash) ⇒ UpdateCheck

Create from hash

Parameters:

  • hash (Hash)

    Serialized update check

Returns:



93
94
95
96
97
98
99
100
101
102
103
# File 'lib/aidp/auto_update/update_check.rb', line 93

def self.from_h(hash)
  new(
    current_version: hash[:current_version] || hash["current_version"],
    available_version: hash[:available_version] || hash["available_version"],
    update_available: hash[:update_available] || hash["update_available"],
    update_allowed: hash[:update_allowed] || hash["update_allowed"],
    policy_reason: hash[:policy_reason] || hash["policy_reason"],
    checked_at: Time.parse(hash[:checked_at] || hash["checked_at"]),
    error: hash[:error] || hash["error"]
  )
end

.unavailable(current_version: Aidp::VERSION) ⇒ UpdateCheck

Create an unavailable update check (service temporarily unavailable)

Parameters:

  • current_version (String) (defaults to: Aidp::VERSION)

    Current version

Returns:



48
49
50
51
52
53
54
55
56
# File 'lib/aidp/auto_update/update_check.rb', line 48

def self.unavailable(current_version: Aidp::VERSION)
  new(
    current_version: current_version,
    available_version: current_version,
    update_available: false,
    update_allowed: false,
    policy_reason: "Update service temporarily unavailable"
  )
end

Instance Method Details

#failed?Boolean

Check if update check failed

Returns:

  • (Boolean)


66
67
68
# File 'lib/aidp/auto_update/update_check.rb', line 66

def failed?
  !success?
end

#should_update?Boolean

Check if update should be performed

Returns:

  • (Boolean)


72
73
74
# File 'lib/aidp/auto_update/update_check.rb', line 72

def should_update?
  success? && @update_available && @update_allowed
end

#success?Boolean

Check if update check was successful

Returns:

  • (Boolean)


60
61
62
# File 'lib/aidp/auto_update/update_check.rb', line 60

def success?
  @error.nil?
end

#to_hHash

Convert to hash for serialization

Returns:

  • (Hash)


78
79
80
81
82
83
84
85
86
87
88
# File 'lib/aidp/auto_update/update_check.rb', line 78

def to_h
  {
    current_version: @current_version,
    available_version: @available_version,
    update_available: @update_available,
    update_allowed: @update_allowed,
    policy_reason: @policy_reason,
    checked_at: @checked_at.utc.iso8601,
    error: @error
  }
end