Class: Bump::Application
- Inherits:
-
Object
- Object
- Bump::Application
- Defined in:
- lib/bump/application.rb
Overview
The application
Instance Method Summary collapse
-
#action_bump ⇒ Boolean
The bump action.
-
#action_help ⇒ void
handler of ‘bmp –help`.
-
#action_info ⇒ void
handler of ‘bmp [–info]`.
-
#action_version ⇒ void
handler of ‘bmp –version`.
-
#bump_level ⇒ Symbol
Gets the requested bump level.
-
#bump_option?(options) ⇒ Boolean
Returns true iff it’s a bump option.
-
#commit_and_tag(bump_info) ⇒ Object
Commits current changes and tag it by the current version.
-
#create_bump_info ⇒ Bump::BumpInfo
Gets the bump info.
-
#initialize(options, help, version, file, logger, command = nil) ⇒ 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.
-
#print_bump_plan(bump_info) ⇒ Object
Prints the version bump plan.
-
#print_bump_plan_level(level, bump_info) ⇒ Object
Prints the bump plan for the given level.
-
#print_bump_plan_preid(preid, bump_info) ⇒ Object
Prints the bump plan for the give preid.
-
#print_bump_plan_release(bump_info) ⇒ Object
Prints the bump plan for the release.
-
#print_invalid_bump_info(bump_info) ⇒ void
Checks the bumping is possible.
-
#print_rule(rule) ⇒ Object
Prints the pattern info for the given rule.
-
#print_version_patterns(bump_info) ⇒ void
Shows the version patterns.
-
#print_version_transition(bump_info) ⇒ Object
Prints the version transition.
-
#report(bump_info) ⇒ Object
Reports the bumping details.
-
#save_bump_info(bump_info) ⇒ void
Saves the bump info.
-
#select_action ⇒ Symbol
Returns a symbol which represents the action to perform.
Constructor Details
#initialize(options, help, version, file, logger, command = nil) ⇒ Application
Returns a new instance of Application.
12 13 14 15 16 17 18 19 20 |
# File 'lib/bump/application.rb', line 12 def initialize(, help, version, file, logger, command = nil) @options = @help = help @version = version @file = file @logger = logger @command = command @command = Bump::Command.new @logger if @command.nil? end |
Instance Method Details
#action_bump ⇒ Boolean
The bump action
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/bump/application.rb', line 158 def action_bump bump_info = create_bump_info return false if bump_info.nil? print_bump_plan bump_info unless bump_info.valid? print_invalid_bump_info bump_info return false end bump_info.perform_update report bump_info save_bump_info bump_info commit_and_tag bump_info if @options[:commit] true end |
#action_help ⇒ void
This method returns an undefined value.
handler of ‘bmp –help`
55 56 57 58 59 |
# File 'lib/bump/application.rb', line 55 def action_help log @help true end |
#action_info ⇒ void
This method returns an undefined value.
handler of ‘bmp [–info]`
124 125 126 127 128 129 130 131 132 |
# File 'lib/bump/application.rb', line 124 def action_info bump_info = create_bump_info return false if bump_info.nil? print_version_patterns bump_info bump_info.valid? end |
#action_version ⇒ void
This method returns an undefined value.
handler of ‘bmp –version`
46 47 48 49 50 |
# File 'lib/bump/application.rb', line 46 def action_version log @version true end |
#bump_level ⇒ Symbol
Gets the requested bump level.
184 185 186 187 188 |
# File 'lib/bump/application.rb', line 184 def bump_level return :major if @options[:major] return :minor if @options[:minor] return :patch if @options[:patch] end |
#bump_option?(options) ⇒ Boolean
Returns true iff it’s a bump option.
39 40 41 |
# File 'lib/bump/application.rb', line 39 def bump_option?() [:major] || [:minor] || [:patch] || [:commit] || [:preid] || [:release] end |
#commit_and_tag(bump_info) ⇒ Object
Commits current changes and tag it by the current version.
241 242 243 244 245 246 |
# File 'lib/bump/application.rb', line 241 def commit_and_tag(bump_info) @logger.log '===> executing commands' @command.exec 'git add .' @command.exec "git commit -m '#{bump_info.}'" @command.exec "git tag v#{bump_info.after_version}" end |
#create_bump_info ⇒ Bump::BumpInfo
Gets the bump info
64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/bump/application.rb', line 64 def create_bump_info repo = BumpInfoRepository.new @file begin bump_info = repo.from_file rescue Errno::ENOENT log_red "Error: the file `#{@file}` not found." return nil end bump_info end |
#log(message = '', newline = true) ⇒ void
This method returns an undefined value.
Logs the message
269 270 271 |
# File 'lib/bump/application.rb', line 269 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
287 288 289 |
# File 'lib/bump/application.rb', line 287 def log_green(, newline = true) log @logger.green(), newline end |
#log_red(message, newline = true) ⇒ void
This method returns an undefined value.
Logs the message in red
278 279 280 |
# File 'lib/bump/application.rb', line 278 def log_red(, newline = true) log @logger.red(), newline end |
#main ⇒ void
This method returns an undefined value.
The entry point
251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/bump/application.rb', line 251 def main case select_action when :version action_version when :help action_help when :info action_info when :bump action_bump end end |
#print_bump_plan(bump_info) ⇒ Object
Prints the version bump plan.
192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/bump/application.rb', line 192 def print_bump_plan(bump_info) level = bump_level print_bump_plan_level level, bump_info unless level.nil? preid = @options[:preid] print_bump_plan_preid preid, bump_info unless preid.nil? print_bump_plan_release bump_info if @options[:release] log end |
#print_bump_plan_level(level, bump_info) ⇒ Object
Prints the bump plan for the given level.
207 208 209 210 211 212 |
# File 'lib/bump/application.rb', line 207 def print_bump_plan_level(level, bump_info) bump_info.bump level log "Bump #{level} level" print_version_transition bump_info end |
#print_bump_plan_preid(preid, bump_info) ⇒ Object
Prints the bump plan for the give preid.
216 217 218 219 220 221 222 |
# File 'lib/bump/application.rb', line 216 def print_bump_plan_preid(preid, bump_info) bump_info.preid = preid log 'Set pre-release version id: ', false log_green preid print_version_transition bump_info end |
#print_bump_plan_release(bump_info) ⇒ Object
Prints the bump plan for the release
226 227 228 229 230 231 |
# File 'lib/bump/application.rb', line 226 def print_bump_plan_release(bump_info) bump_info.preid = nil log 'Remove pre-release version id' print_version_transition bump_info end |
#print_invalid_bump_info(bump_info) ⇒ void
This method returns an undefined value.
Checks the bumping is possible.
137 138 139 140 141 142 143 |
# File 'lib/bump/application.rb', line 137 def print_invalid_bump_info(bump_info) log_red 'Some patterns are invalid!' log_red 'Stops updating version numbers.' log print_version_patterns bump_info end |
#print_rule(rule) ⇒ Object
Prints the pattern info for the given rule
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/bump/application.rb', line 102 def print_rule(rule) unless rule.file_exists log_red " #{rule.file}:", false log_red " '#{rule.before_pattern}' (file not found)" return end log " #{rule.file}:", false unless rule.pattern_exists log_red " '#{rule.before_pattern}' (pattern not found)" return end log_green " '#{rule.before_pattern}'" end |
#print_version_patterns(bump_info) ⇒ void
This method returns an undefined value.
Shows the version patterns.
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/bump/application.rb', line 89 def print_version_patterns(bump_info) log 'Current Version:', false log_green " #{bump_info.before_version}" log 'Version patterns:' bump_info.update_rules.each do |rule| print_rule rule end end |
#print_version_transition(bump_info) ⇒ Object
Prints the version transition.
235 236 237 |
# File 'lib/bump/application.rb', line 235 def print_version_transition(bump_info) log_green " #{bump_info.before_version} => #{bump_info.after_version}" end |
#report(bump_info) ⇒ Object
Reports the bumping details.
147 148 149 150 151 152 153 154 |
# File 'lib/bump/application.rb', line 147 def report(bump_info) bump_info.update_rules.each do |rule| log rule.file.to_s log ' Performed pattern replacement:' log_green " '#{rule.before_pattern}' => '#{rule.after_pattern}'" log end end |
#save_bump_info(bump_info) ⇒ void
This method returns an undefined value.
Saves the bump info
80 81 82 83 84 |
# File 'lib/bump/application.rb', line 80 def save_bump_info(bump_info) repo = BumpInfoRepository.new @file repo.save bump_info end |
#select_action ⇒ Symbol
Returns a symbol which represents the action to perform.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/bump/application.rb', line 24 def select_action return :help if @options[:help] return :version if @options[:version] return :info if @options[:info] return :bump if bump_option? @options # command without options invokes info action :info end |