Class: Bump::Application
- Inherits:
-
Object
- Object
- Bump::Application
- Defined in:
- lib/bump/application.rb
Overview
The application
Instance Method Summary collapse
-
#actionBump ⇒ void
handler of ‘bmp –patch|–minor|–major|–commit`.
-
#actionHelp ⇒ void
handler of ‘bmp –help`.
-
#actionInfo ⇒ void
handler of ‘bmp [–info]`.
-
#actionVersion ⇒ void
handler of ‘bmp –version`.
-
#checkBumpInfo(bumpInfo) ⇒ void
Checks the bumping is possible.
-
#getBumpInfo ⇒ Bump::BumpInfo
Gets the bump info.
-
#initialize(options, help, version, file, logger) ⇒ Application
constructor
A new instance of Application.
-
#log(message = '', newline = true) ⇒ void
Logs the message.
-
#log_green(message, newline = true) ⇒ void
Logs the message in green.
-
#log_red(message, newline = true) ⇒ void
Logs the message in red.
-
#main ⇒ void
The entry point.
-
#report(bumpInfo) ⇒ void
Reports the bumping details.
-
#saveBumpInfo(bumpInfo) ⇒ void
Saves the bump info.
-
#selectAction ⇒ Symbol
Returns a symbol which represents the action to perform.
-
#showVersionPatterns(bumpInfo) ⇒ void
Shows the version patterns.
Constructor Details
#initialize(options, help, version, file, logger) ⇒ Application
Returns a new instance of Application.
15 16 17 18 19 20 21 |
# File 'lib/bump/application.rb', line 15 def initialize , help, version, file, logger @options = @help = help @version = version @file = file @logger = logger end |
Instance Method Details
#actionBump ⇒ void
This method returns an undefined value.
handler of ‘bmp –patch|–minor|–major|–commit`
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/bump/application.rb', line 166 def actionBump bumpInfo = getBumpInfo [:major, :minor, :patch].each do |level| if @options[level] bumpInfo.bump level log "Bump #{level} level" log_green " #{bumpInfo.beforeVersion} => #{bumpInfo.afterVersion}" break end end if @options[:preid] preid = @options[:preid] bumpInfo.setPreid preid log "Set pre-release version id: ", false log_green preid log_green " #{bumpInfo.beforeVersion} => #{bumpInfo.afterVersion}" end log checkBumpInfo bumpInfo bumpInfo.performUpdate report bumpInfo saveBumpInfo bumpInfo comm = Command.new @logger if @options[:commit] comm.exec "git add ." comm.exec "git commit -m 'Bump to version v#{bumpInfo.afterVersion}'" comm.exec "git tag v#{bumpInfo.afterVersion}" end end |
#actionHelp ⇒ void
This method returns an undefined value.
handler of ‘bmp –help`
57 58 59 |
# File 'lib/bump/application.rb', line 57 def actionHelp log @help end |
#actionInfo ⇒ void
This method returns an undefined value.
handler of ‘bmp [–info]`
115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/bump/application.rb', line 115 def actionInfo bumpInfo = getBumpInfo showVersionPatterns bumpInfo if bumpInfo.check exit 0 else exit 1 end end |
#actionVersion ⇒ void
This method returns an undefined value.
handler of ‘bmp –version`
50 51 52 |
# File 'lib/bump/application.rb', line 50 def actionVersion log @version end |
#checkBumpInfo(bumpInfo) ⇒ void
This method returns an undefined value.
Checks the bumping is possible.
134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/bump/application.rb', line 134 def checkBumpInfo bumpInfo if not bumpInfo.check log_red "Some patterns are invalid!" log_red "Stops updating version numbers." log showVersionPatterns bumpInfo exit 1 end end |
#getBumpInfo ⇒ Bump::BumpInfo
Gets the bump info
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/bump/application.rb', line 64 def getBumpInfo repo = BumpInfoRepository.new @file begin bumpInfo = repo.fromFile rescue Errno::ENOENT => e then log_red "Error: the file `#{@file}` not found." exit 1 end return bumpInfo end |
#log(message = '', newline = true) ⇒ void
This method returns an undefined value.
Logs the message
231 232 233 234 235 |
# File 'lib/bump/application.rb', line 231 def log = '', newline = true @logger.log , newline end |
#log_green(message, newline = true) ⇒ void
This method returns an undefined value.
Logs the message in green
253 254 255 256 257 |
# File 'lib/bump/application.rb', line 253 def log_green , newline = true @logger.log_green , newline end |
#log_red(message, newline = true) ⇒ void
This method returns an undefined value.
Logs the message in red
242 243 244 245 246 |
# File 'lib/bump/application.rb', line 242 def log_red , newline = true @logger.log_red , newline end |
#main ⇒ void
This method returns an undefined value.
The entry point
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/bump/application.rb', line 209 def main action = selectAction case action when :version actionVersion when :help actionHelp when :info actionInfo when :bump actionBump end end |
#report(bumpInfo) ⇒ void
This method returns an undefined value.
Reports the bumping details.
152 153 154 155 156 157 158 159 160 161 |
# File 'lib/bump/application.rb', line 152 def report bumpInfo bumpInfo.updateRules.each do |rule| log "#{rule.file}" log " Performed pattern replacement:" log_green " '#{rule.beforePattern}' => '#{rule.afterPattern}'" log end end |
#saveBumpInfo(bumpInfo) ⇒ void
This method returns an undefined value.
Saves the bump info
83 84 85 86 87 |
# File 'lib/bump/application.rb', line 83 def saveBumpInfo bumpInfo repo = BumpInfoRepository.new @file repo.save bumpInfo end |
#selectAction ⇒ Symbol
Returns a symbol which represents the action to perform.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/bump/application.rb', line 26 def selectAction if @options[:help] return :help end if @options[:version] return :version end if @options[:info] return :info end if @options[:major] || @options[:minor] || @options[:patch] || @options[:commit] || @options[:preid] return :bump end # command without options invokes info action return :info end |
#showVersionPatterns(bumpInfo) ⇒ void
This method returns an undefined value.
Shows the version patterns.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/bump/application.rb', line 93 def showVersionPatterns bumpInfo log "Current Version:", false log_green " #{bumpInfo.beforeVersion}" log "Version patterns:" bumpInfo.updateRules.each do |rule| log " #{rule.file}:", false if rule.patternExists log_green " '#{rule.beforePattern}'" else log_red " '#{rule.beforePattern}' (pattern not found)" end end end |