Class: Aidp::AutoUpdate::VersionDetector

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

Overview

Service for detecting available gem versions and enforcing semver policy

Instance Method Summary collapse

Constructor Details

#initialize(policy:, current_version: Aidp::VERSION, bundler_adapter: BundlerAdapter.new, rubygems_adapter: RubyGemsAPIAdapter.new) ⇒ VersionDetector

Returns a new instance of VersionDetector.



12
13
14
15
16
17
18
19
20
21
# File 'lib/aidp/auto_update/version_detector.rb', line 12

def initialize(
  policy:, current_version: Aidp::VERSION,
  bundler_adapter: BundlerAdapter.new,
  rubygems_adapter: RubyGemsAPIAdapter.new
)
  @current_version = Gem::Version.new(current_version)
  @policy = policy
  @bundler_adapter = bundler_adapter
  @rubygems_adapter = rubygems_adapter
end

Instance Method Details

#check_for_updateUpdateCheck

Check for updates according to policy

Returns:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/aidp/auto_update/version_detector.rb', line 25

def check_for_update
  Aidp.log_info("version_detector", "checking_for_updates",
    current_version: @current_version.to_s,
    policy: @policy.policy)

  available_version = fetch_latest_version

  unless available_version
    Aidp.log_warn("version_detector", "no_version_available")
    return UpdateCheck.unavailable(current_version: @current_version.to_s)
  end

  update_available = available_version > @current_version
  # Check policy even if disabled - we still want to report update_available
  update_allowed = @policy.disabled? ? false : update_allowed_by_policy?(available_version)
  reason = policy_reason(available_version)

  Aidp.log_info("version_detector", "update_check_complete",
    current: @current_version.to_s,
    available: available_version.to_s,
    update_available: update_available,
    update_allowed: update_allowed,
    reason: reason)

  UpdateCheck.new(
    current_version: @current_version.to_s,
    available_version: available_version.to_s,
    update_available: update_available,
    update_allowed: update_allowed,
    policy_reason: reason
  )
rescue => e
  Aidp.log_error("version_detector", "check_failed", error: e.message)
  UpdateCheck.failed(e.message, current_version: @current_version.to_s)
end