Class: GemCheckUpdates::Gem
- Inherits:
-
Object
- Object
- GemCheckUpdates::Gem
- Defined in:
- lib/gem_check_updates/gem.rb
Constant Summary collapse
- DEFAULT_SCOPE =
GemCheckUpdates::VersionScope::MAJOR
Instance Attribute Summary collapse
-
#current_version ⇒ Object
Returns the value of attribute current_version.
-
#latest_version ⇒ Object
Returns the value of attribute latest_version.
-
#name ⇒ Object
Returns the value of attribute name.
-
#version_range ⇒ Object
Returns the value of attribute version_range.
Instance Method Summary collapse
- #highlighted_latest_version ⇒ Object
-
#initialize(name: nil, current_version: nil, version_range: nil, latest_version: nil, update_scope: DEFAULT_SCOPE) ⇒ Gem
constructor
A new instance of Gem.
- #scoped_latest_version(versions) ⇒ Object
- #update_available? ⇒ Boolean
Constructor Details
#initialize(name: nil, current_version: nil, version_range: nil, latest_version: nil, update_scope: DEFAULT_SCOPE) ⇒ Gem
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/gem_check_updates/gem.rb', line 12 def initialize(name: nil, current_version: nil, version_range: nil, latest_version: nil, update_scope: DEFAULT_SCOPE) @name = name @current_version = current_version @version_range = version_range @latest_version = latest_version @update_scope = update_scope end |
Instance Attribute Details
#current_version ⇒ Object
Returns the value of attribute current_version.
9 10 11 |
# File 'lib/gem_check_updates/gem.rb', line 9 def current_version @current_version end |
#latest_version ⇒ Object
Returns the value of attribute latest_version.
8 9 10 |
# File 'lib/gem_check_updates/gem.rb', line 8 def latest_version @latest_version end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/gem_check_updates/gem.rb', line 7 def name @name end |
#version_range ⇒ Object
Returns the value of attribute version_range.
10 11 12 |
# File 'lib/gem_check_updates/gem.rb', line 10 def version_range @version_range end |
Instance Method Details
#highlighted_latest_version ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/gem_check_updates/gem.rb', line 53 def highlighted_latest_version Array.new(3) do |i| c = @current_version.split('.')[i] l = @latest_version.split('.')[i] c == l ? l : l.green end.join('.') end |
#scoped_latest_version(versions) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/gem_check_updates/gem.rb', line 31 def scoped_latest_version(versions) # Ignore pre release version (ex. beta, rc), and sort desc numbers = versions.map { |v| v['number'] } .select { |v| v.split('.').size < 4 } .sort_by { |v| v.split('.').map(&:to_i)[0, 3] } .reverse current_major, current_minor = @current_version.split('.') case @update_scope when GemCheckUpdates::VersionScope::MINOR numbers.select { |n| n.split('.').first == current_major }.first when GemCheckUpdates::VersionScope::PATCH numbers.select do |n| major, minor = n.split('.') major == current_major && minor == current_minor end.first else # This branch is equal to specifying major updates numbers.first end end |
#update_available? ⇒ Boolean
24 25 26 27 28 29 |
# File 'lib/gem_check_updates/gem.rb', line 24 def update_available? !@latest_version.nil? && !@current_version.nil? && @current_version != '0' && @latest_version > @current_version end |