Class: Bundler::Interactive::OutdatedGem
- Inherits:
-
Object
- Object
- Bundler::Interactive::OutdatedGem
- 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
-
#dependency ⇒ Object
readonly
Returns the value of attribute dependency.
-
#latest_version ⇒ Object
readonly
Returns the value of attribute latest_version.
-
#pending_version ⇒ Object
readonly
Returns the value of attribute pending_version.
-
#selected_index ⇒ Object
readonly
Returns the value of attribute selected_index.
Instance Method Summary collapse
- #choices ⇒ Object
-
#cooldown_note ⇒ Object
Informational note for an in-range update that is being withheld by the cooldown window but is not otherwise visible as a selectable choice.
-
#cross_constraint? ⇒ Boolean
The selected target is newer than the Gemfile constraint allows, so the Gemfile requirement must be rewritten before updating.
- #current_version ⇒ Object
- #cycle_left ⇒ Object
- #cycle_right ⇒ Object
- #git_changed? ⇒ Boolean
-
#group_label ⇒ Object
Only the noteworthy groups; the implicit :default group renders as blank.
- #groups ⇒ Object
-
#initialize(current_spec:, resolved_spec:, dependency:, latest_version: nil, pending_version: nil, cooldown_active: false) ⇒ OutdatedGem
constructor
A new instance of OutdatedGem.
- #name(padding = 0) ⇒ Object
- #resolved_version ⇒ Object
- #select_current! ⇒ Object
-
#select_upgrade! ⇒ Object
Jump to the best upgrade target (in-range latest, else absolute latest).
- #selected ⇒ Object
- #selected_version ⇒ Object
-
#skip? ⇒ Boolean
A row is "skipped" (left untouched) when the highlighted choice is the currently installed version.
-
#upgradable? ⇒ Boolean
True when there is anything to pick beyond the installed version.
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
#dependency ⇒ Object (readonly)
Returns the value of attribute dependency.
26 27 28 |
# File 'lib/bundler/interactive/outdated_gem.rb', line 26 def dependency @dependency end |
#latest_version ⇒ Object (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_version ⇒ Object (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_index ⇒ Object (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
#choices ⇒ Object
49 50 51 |
# File 'lib/bundler/interactive/outdated_gem.rb', line 49 def choices @choices ||= build_choices end |
#cooldown_note ⇒ Object
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.
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_version ⇒ Object
41 42 43 |
# File 'lib/bundler/interactive/outdated_gem.rb', line 41 def current_version current_spec.version end |
#cycle_left ⇒ Object
66 67 68 |
# File 'lib/bundler/interactive/outdated_gem.rb', line 66 def cycle_left @selected_index = (@selected_index - 1) % choices.size end |
#cycle_right ⇒ Object
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
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_label ⇒ Object
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 |
#groups ⇒ Object
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_version ⇒ Object
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 |
#selected ⇒ Object
58 59 60 |
# File 'lib/bundler/interactive/outdated_gem.rb', line 58 def selected choices[@selected_index] end |
#selected_version ⇒ Object
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.
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.
54 55 56 |
# File 'lib/bundler/interactive/outdated_gem.rb', line 54 def upgradable? choices.size > 1 end |