Class: BundleUpdateInteractive::SemverChange
- Inherits:
-
Object
- Object
- BundleUpdateInteractive::SemverChange
- Defined in:
- lib/bundle_update_interactive/semver_change.rb
Constant Summary collapse
- SEVERITIES =
%i[major minor patch].freeze
Instance Method Summary collapse
- #any? ⇒ Boolean
- #format ⇒ Object
-
#initialize(old_version, new_version) ⇒ SemverChange
constructor
A new instance of SemverChange.
- #none? ⇒ Boolean
- #severity ⇒ Object
Constructor Details
#initialize(old_version, new_version) ⇒ SemverChange
Returns a new instance of SemverChange.
7 8 9 10 11 12 13 14 15 |
# File 'lib/bundle_update_interactive/semver_change.rb', line 7 def initialize(old_version, new_version) old_segments = old_version.to_s.split(".") new_segments = new_version.to_s.split(".") @same_segments = new_segments.take_while.with_index { |seg, i| seg == old_segments[i] } @diff_segments = new_segments[same_segments.length..] @changed = diff_segments.any? || old_segments.length != new_segments.length end |
Instance Method Details
#any? ⇒ Boolean
31 32 33 |
# File 'lib/bundle_update_interactive/semver_change.rb', line 31 def any? !!severity end |
#format ⇒ Object
35 36 37 38 39 40 |
# File 'lib/bundle_update_interactive/semver_change.rb', line 35 def format parts = [] parts << same_segments.join(".") if same_segments.any? parts << yield(diff_segments.join(".")) if diff_segments.any? parts.join(".") end |
#none? ⇒ Boolean
27 28 29 |
# File 'lib/bundle_update_interactive/semver_change.rb', line 27 def none? severity.nil? end |
#severity ⇒ Object
17 18 19 20 21 |
# File 'lib/bundle_update_interactive/semver_change.rb', line 17 def severity return nil unless @changed SEVERITIES[same_segments.length] || :patch end |