Class: Blufin::Versioning

Inherits:
Object
  • Object
show all
Defined in:
lib/core/versioning.rb

Constant Summary collapse

VERSION_REGEX =
/\d{1,3}\.\d{1,3}\.\d{0,3}/

Class Method Summary collapse

Class Method Details

.get_new_version_from_prompt(title, current_version, capitalize_tile: true) ⇒ Object

Shows prompt to let you select a new major, minor or patch version.

Returns:

  • string


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/core/versioning.rb', line 9

def self.get_new_version_from_prompt(title, current_version, capitalize_tile: true)
    Blufin::Terminal::error("Current version does not match regex: #{current_version}", "Expected something like: #{Blufin::Terminal::format_highlight('12.1.0')}", true) unless current_version =~ VERSION_REGEX
    vp = current_version.split('.')
    color1 = 246
    color2 = 40
    patch = "\x1B[38;5;#{color1}mPatch \x1B[38;5;242m\xe2\x80\x94 \x1B[38;5;#{color2}m#{vp[0]}.#{vp[1]}.#{vp[2].to_i + 1} \x1B[38;5;242m\xe2\x80\x94\x1B[38;5;240m New version is interchangeable, users can upgrade/downgrade freely."
    minor = "\x1B[38;5;#{color1}mMinor \x1B[38;5;242m\xe2\x80\x94 \x1B[38;5;#{color2}m#{vp[0]}.#{vp[1].to_i + 1}.0 \x1B[38;5;242m\xe2\x80\x94\x1B[38;5;240m New version is backwards compatible, users can upgrade freely."
    major = "\x1B[38;5;#{color1}mMajor \x1B[38;5;242m\xe2\x80\x94 \x1B[38;5;#{color2}m#{vp[0].to_i + 1}.0.0 \x1B[38;5;242m\xe2\x80\x94\x1B[38;5;240m New version has breaking API changes, users #{Blufin::Terminal::format_invalid('CANNOT')}\x1B[38;5;240m upgrade without making code changes."
    options = [
        {:text => patch, :value => "#{vp[0]}.#{vp[1]}.#{vp[2].to_i + 1}"},
        {:text => minor, :value => "#{vp[0]}.#{vp[1].to_i + 1}.0"},
        {:text => major, :value => "#{vp[0].to_i + 1}.0.0"}
    ]
    title = title.upcase if capitalize_tile
    Blufin::Terminal::custom(title, nil, "Current version is: #{Blufin::Terminal::format_highlight(current_version)}")
    Blufin::Terminal::prompt_select('Choose new semantic version:', options)
end