Class: Bump::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/bump/application.rb

Overview

The application

Instance Method Summary collapse

Constructor Details

#initialize(options, help, version, file, logger) ⇒ Application

Returns a new instance of Application.

Parameters:

  • options (Hash)

    The cli options

  • help (String)

    The help message

  • version (String)

    The version expression of this command

  • file (String)

    The file name of bump info file

  • logger (Bump::Logger)

    The logger



15
16
17
18
19
20
21
# File 'lib/bump/application.rb', line 15

def initialize options, help, version, file, logger
    @options = options
    @help = help
    @version = version
    @file = file
    @logger = logger
end

Instance Method Details

#actionBumpvoid

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

#actionHelpvoid

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

#actionInfovoid

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

#actionVersionvoid

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.

Parameters:



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

#getBumpInfoBump::BumpInfo

Gets the bump info

Returns:



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

Parameters:

  • message (String) (defaults to: '')
  • newline (Boolean) (defaults to: true)


231
232
233
234
235
# File 'lib/bump/application.rb', line 231

def log message = '', newline = true

    @logger.log message, newline

end

#log_green(message, newline = true) ⇒ void

This method returns an undefined value.

Logs the message in green

Parameters:

  • message (String)
  • newline (Boolean) (defaults to: true)


253
254
255
256
257
# File 'lib/bump/application.rb', line 253

def log_green message, newline = true

    @logger.log_green message, newline

end

#log_red(message, newline = true) ⇒ void

This method returns an undefined value.

Logs the message in red

Parameters:

  • message (String)
  • newline (Boolean) (defaults to: true)


242
243
244
245
246
# File 'lib/bump/application.rb', line 242

def log_red message, newline = true

    @logger.log_red message, newline

end

#mainvoid

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.

Parameters:



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

Parameters:



83
84
85
86
87
# File 'lib/bump/application.rb', line 83

def saveBumpInfo bumpInfo
    repo = BumpInfoRepository.new @file

    repo.save bumpInfo
end

#selectActionSymbol

Returns a symbol which represents the action to perform.

Returns:

  • (Symbol)


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.

Parameters:



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