Class: Bundler::Interactive::OutdatedGem

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/interactive/outdated_gem.rb

Overview

View-model for a single outdated gem row in the interactive table.

It exposes an ordered, de-duplicated list of selectable version choices (current -> in-range latest -> absolute latest) and tracks which one the user has highlighted. The renderer cycles the selection with +cycle_left+/+cycle_right+ and reads selected_version when applying.

Defined Under Namespace

Classes: Choice

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_spec:, resolved_spec:, dependency:, latest_version: nil, pending_version: nil, cooldown_active: false) ⇒ OutdatedGem

Returns a new instance of OutdatedGem.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bundler/interactive/outdated_gem.rb', line 14

def initialize(current_spec:, resolved_spec:, dependency:,
               latest_version: nil, pending_version: nil,
               cooldown_active: false)
  @current_spec = current_spec
  @resolved_spec = resolved_spec
  @dependency = dependency
  @latest_version = latest_version || resolved_spec.version
  @pending_version = pending_version
  @cooldown_active = cooldown_active
  @selected_index = default_index
end

Instance Attribute Details

#dependencyObject (readonly)

Returns the value of attribute dependency.



26
27
28
# File 'lib/bundler/interactive/outdated_gem.rb', line 26

def dependency
  @dependency
end

#latest_versionObject (readonly)

Returns the value of attribute latest_version.



26
27
28
# File 'lib/bundler/interactive/outdated_gem.rb', line 26

def latest_version
  @latest_version
end

#pending_versionObject (readonly)

Returns the value of attribute pending_version.



26
27
28
# File 'lib/bundler/interactive/outdated_gem.rb', line 26

def pending_version
  @pending_version
end

#selected_indexObject (readonly)

Returns the value of attribute selected_index.



26
27
28
# File 'lib/bundler/interactive/outdated_gem.rb', line 26

def selected_index
  @selected_index
end

Instance Method Details

#choicesObject



49
50
51
# File 'lib/bundler/interactive/outdated_gem.rb', line 49

def choices
  @choices ||= build_choices
end

#cooldown_noteObject

Informational note for an in-range update that is being withheld by the cooldown window but is not otherwise visible as a selectable choice.



106
107
108
109
110
111
112
# File 'lib/bundler/interactive/outdated_gem.rb', line 106

def cooldown_note
  return nil unless @cooldown_active
  return nil unless pending_version
  return nil if choices.any?(&:held)

  "#{pending_version} held by cooldown"
end

#cross_constraint?Boolean

The selected target is newer than the Gemfile constraint allows, so the Gemfile requirement must be rewritten before updating.

Returns:

  • (Boolean)


97
98
99
100
101
102
# File 'lib/bundler/interactive/outdated_gem.rb', line 97

def cross_constraint?
  return false unless dependency
  return false if git_changed?

  !dependency.requirement.satisfied_by?(selected_version)
end

#current_versionObject



41
42
43
# File 'lib/bundler/interactive/outdated_gem.rb', line 41

def current_version
  current_spec.version
end

#cycle_leftObject



66
67
68
# File 'lib/bundler/interactive/outdated_gem.rb', line 66

def cycle_left
  @selected_index = (@selected_index - 1) % choices.size
end

#cycle_rightObject



70
71
72
# File 'lib/bundler/interactive/outdated_gem.rb', line 70

def cycle_right
  @selected_index = (@selected_index + 1) % choices.size
end

#git_changed?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'lib/bundler/interactive/outdated_gem.rb', line 91

def git_changed?
  current_git != resolved_git && !(current_git.nil? && resolved_git.nil?)
end

#group_labelObject

Only the noteworthy groups; the implicit :default group renders as blank.



37
38
39
# File 'lib/bundler/interactive/outdated_gem.rb', line 37

def group_label
  (groups.map(&:to_s) - ['default']).join(',')
end

#groupsObject



32
33
34
# File 'lib/bundler/interactive/outdated_gem.rb', line 32

def groups
  dependency ? Array(dependency.groups) : []
end

#name(padding = 0) ⇒ Object



28
29
30
# File 'lib/bundler/interactive/outdated_gem.rb', line 28

def name(padding = 0)
  current_spec.name.ljust(padding)
end

#resolved_versionObject



45
46
47
# File 'lib/bundler/interactive/outdated_gem.rb', line 45

def resolved_version
  resolved_spec.version
end

#select_current!Object



74
75
76
# File 'lib/bundler/interactive/outdated_gem.rb', line 74

def select_current!
  @selected_index = choices.index { |choice| choice.role == :current } || 0
end

#select_upgrade!Object

Jump to the best upgrade target (in-range latest, else absolute latest).



79
80
81
82
83
# File 'lib/bundler/interactive/outdated_gem.rb', line 79

def select_upgrade!
  index = choices.index { |choice| choice.role == :in_range } ||
          choices.index { |choice| choice.role == :latest }
  @selected_index = index if index
end

#selectedObject



58
59
60
# File 'lib/bundler/interactive/outdated_gem.rb', line 58

def selected
  choices[@selected_index]
end

#selected_versionObject



62
63
64
# File 'lib/bundler/interactive/outdated_gem.rb', line 62

def selected_version
  selected.version
end

#skip?Boolean

A row is "skipped" (left untouched) when the highlighted choice is the currently installed version.

Returns:

  • (Boolean)


87
88
89
# File 'lib/bundler/interactive/outdated_gem.rb', line 87

def skip?
  selected.role == :current
end

#upgradable?Boolean

True when there is anything to pick beyond the installed version.

Returns:

  • (Boolean)


54
55
56
# File 'lib/bundler/interactive/outdated_gem.rb', line 54

def upgradable?
  choices.size > 1
end