Class: BundleUpdateInteractive::SemverChange

Inherits:
Object
  • Object
show all
Defined in:
lib/bundle_update_interactive/semver_change.rb

Constant Summary collapse

SEVERITIES =
%i[major minor patch].freeze

Instance Method Summary collapse

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

Returns:

  • (Boolean)


31
32
33
# File 'lib/bundle_update_interactive/semver_change.rb', line 31

def any?
  !!severity
end

#formatObject



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

Returns:

  • (Boolean)


27
28
29
# File 'lib/bundle_update_interactive/semver_change.rb', line 27

def none?
  severity.nil?
end

#severityObject



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