Class: Bump::Bump
- Inherits:
-
Object
- Object
- Bump::Bump
- Defined in:
- lib/bump.rb
Constant Summary collapse
- BUMPS =
["major", "minor", "patch", "pre"].freeze
- PRERELEASE =
["alpha", "beta", "rc", nil].freeze
- OPTIONS =
BUMPS | ["set", "current", "file"]
- VERSION_REGEX =
/(\d+\.\d+\.\d+(?:-(?:#{PRERELEASE.compact.join('|')}))?)/.freeze
Class Method Summary collapse
- .current ⇒ Object
- .defaults ⇒ Object
- .file ⇒ Object
- .next_version(increment, current = Bump.current) ⇒ Object
- .parse_cli_options!(options) ⇒ Object
- .run(bump, options = {}) ⇒ Object
Class Method Details
.current ⇒ Object
71 72 73 |
# File 'lib/bump.rb', line 71 def current current_info.first end |
.defaults ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bump.rb', line 23 def defaults { tag: ::Bump.tag_by_default, tag_prefix: 'v', commit: true, changelog: ::Bump.changelog || false, # TODO: default to true with opt-out once it gets more stable bundle: File.exist?("Gemfile"), replace_in: ::Bump.replace_in_default || [] } end |
.file ⇒ Object
100 101 102 |
# File 'lib/bump.rb', line 100 def file current_info.last end |
.next_version(increment, current = Bump.current) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/bump.rb', line 75 def next_version(increment, current = Bump.current) current, prerelease = current.split('-') major, minor, patch, *other = current.split('.') case increment when "major" major = major.succ minor = 0 patch = 0 prerelease = nil when "minor" minor = minor.succ patch = 0 prerelease = nil when "patch" patch = patch.succ when "pre" prerelease.strip! if prerelease.respond_to? :strip prerelease = PRERELEASE[PRERELEASE.index(prerelease).succ % PRERELEASE.length] else raise InvalidIncrementError end version = [major, minor, patch, *other].compact.join('.') [version, prerelease].compact.join('-') end |
.parse_cli_options!(options) ⇒ Object
104 105 106 107 108 109 |
# File 'lib/bump.rb', line 104 def () .each do |key, value| [key] = (value) end .delete_if { |_key, value| value.nil? } end |
.run(bump, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/bump.rb', line 34 def run(bump, = {}) = defaults.merge() [:commit] = false unless File.directory?(".git") case bump when *BUMPS bump_part(bump, ) when "set" raise InvalidVersionError unless [:version] bump_set([:version], ) when "current" [current, 0] when "show-next" increment = [:increment] raise InvalidIncrementError unless BUMPS.include?(increment) [next_version(increment), 0] when "file" [file, 0] else raise InvalidOptionError end rescue InvalidIncrementError ["Invalid increment. Choose between #{BUMPS.join(',')}.", 1] rescue InvalidOptionError ["Invalid option. Choose between #{OPTIONS.join(',')}.", 1] rescue InvalidVersionError ["Invalid version number given.", 1] rescue UnfoundVersionError ["Unable to find your gem version", 1] rescue UnfoundVersionFileError ["Unable to find a file with the gem version", 1] rescue TooManyVersionFilesError ["More than one version file found (#{$!.})", 1] end |