Class: Release::Gem::Cli::GemAction

Inherits:
Object
  • Object
show all
Defined in:
lib/release/gem/gem_cli_action.rb

Instance Method Summary collapse

Constructor Details

#initialize(root, opts = {}) ⇒ GemAction

Returns a new instance of GemAction.



11
12
13
14
15
16
17
18
# File 'lib/release/gem/gem_cli_action.rb', line 11

def initialize(root, opts = {})
  opts = {  } if opts.nil?
  opts[:ui] = TTY::Prompt.new
  @inst = Action::GemAction.new(root, opts)
  @pmt = opts[:tty] || opts[:ui]
  @msgColor = opts[:msgColor] || :yellow 
  @discardColor = opts[:discardColor] || false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mtd, *args, &block) ⇒ Object

install



296
297
298
# File 'lib/release/gem/gem_cli_action.rb', line 296

def method_missing(mtd, *args, &block)
  @inst.send(mtd,*args, &block)
end

Instance Method Details

#build(*pargs, &block) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/release/gem/gem_cli_action.rb', line 142

def build(*pargs, &block)

  @inst.build do |ops, *args|
    case ops
    when :action_start
      @pmt.say pmsg(" Gem building starting...\n")
    when :select_version
      preset = false
      if block
        res = block.call(ops, *args)
        if res.nil?
          preset = true
        else
          res
        end
      else
        preset = true
      end

      if preset

        opts = args.first
        res = @pmt.select(pmsg("\n Please select new gem version : \n"), filter: true) do |m|
          opts[:proposed_next].reverse.each do |v|
            m.choice v,v
          end
          m.choice "#{opts[:current_version]} -> Current version ", opts[:current_version]
          m.choice "Custom version", :custom
          m.choice "Abort", :abort
        end

        raise Release::Gem::Abort, "Abort by user" if res == :abort

        if res == :custom
          loop do
            res = @pmt.ask(pmsg("\n Please provide custom version number for the release : "),required: true)
            confirmed = @pmt.yes?(pmsg("\n Use version '#{res}'? No to try again"))
            break if confirmed
          end
        end

      end # if preset

      res

    when :multiple_version_files_found
      preset = false
      if block
        res = block.call(ops, *args)
        if res.nil?
          preset = true
        else
          res
        end
      else
        preset = true
      end

      if preset

        res = @pmt.select(pmsg("\n There are multiple version file found. Please select which one to update : ")) do |m|
          opts = args.first
          opts.each do |f|
            m.choice f,f
          end
          m.choice "Abort", :abort
        end

        raise Release::Gem::Abort, "Abort by user" if res == :abort
      end

      res
    when :new_version_number
      @selVersion = args.first

    when :gem_build_successfully
      @pmt.puts pmsg("\n Gem version '#{args.first}' built successfully", :green)
      @inst.register(:selected_version, args.first)
      [true, args.first]
    end
  end


end

#exec(&block) ⇒ Object



20
21
22
# File 'lib/release/gem/gem_cli_action.rb', line 20

def exec(&block)
  instance_eval(&block) if block
end

#install(*args, &block) ⇒ Object

push



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/release/gem/gem_cli_action.rb', line 265

def install(*args, &block)

  sysInst = @pmt.yes?(pmsg("\n Install release into system? "))
  if sysInst
    @inst.install(*args) do |ops, *args|
      case ops
      when :multiple_target_gems_found
        files = args.first
        res = @pmt.select("\n It seems there are more than 1 gem files with the same version name : ".yellow) do |m|
          files.each do |k,v|
            m.choice k,v
          end
          m.choice "Abort", :abort
        end

        raise Gem::Release::Abort, "Abort by user" if res == :abort

        res

      when :gem_file_installed
        @pmt.puts "\n Gem file #{args.first} installed successfully ".green

      when :target_gem_not_found
        @pmt.puts "\n There is no gem file fould that has the version '#{args.first}' in its name. Please try again\n".red

      end
    end
  end

end

#pastelObject



316
317
318
# File 'lib/release/gem/gem_cli_action.rb', line 316

def pastel
  Gem.pastel
end

#pmsg(msg, color = nil) ⇒ Object



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
# File 'lib/release/gem/gem_cli_action.rb', line 300

def pmsg(msg, color = nil)
  if not msg.nil?
    if @discardColor == true
      msg
    else
      if not_empty?(color)
        msg.send(color)
      elsif not_empty?(@msgColor)
        msg.send(@msgColor)
      else
        msg
      end
    end
  end
end

#push(*pargs, &block) ⇒ Object

build



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/release/gem/gem_cli_action.rb', line 227

def push(*pargs, &block)
  @inst.push(*pargs) do |ops, *args|
    case ops
    when :confirm_proceed
      name = args.first
      ver = args[1]
      @pmt.yes?(" Push gem '#{name}' version #{ver} to Rubygems? ")

    when :multiple_rubygems_account
      creds = args.first
      res = @pmt.select(pmsg("\n Multiple rubygems account detected. Please select one : ")) do |m|
        creds.each do |k,v|
          m.choice k,k
        end
        m.choice "Skip gem push", :skip
        m.choice "Abort", :abort
      end

      raise Release::Gem::Abort, "Abort by user" if res == :abort
      res

    when :gem_push_output
      st = args.first
      res = args[1]
      if st
        @pmt.puts pmsg("\n Gem push successful. #{res}", :green)
      else
        @pmt.puts pmsg("\n Gem push failed. Error was :\n #{res}", :red)
      end

    when :gem_push_skipped
      @pmt.puts pmsg("\n Gem push skipped", :yellow)

    end
  end

end

#release_dependenciesObject

proxy method for Action::GemAction#release_dependencies



25
26
27
28
29
30
31
32
33
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/release/gem/gem_cli_action.rb', line 25

def release_dependencies
  @inst.release_dependencies do |ops, *args|
   case ops
    when :action_start
      @pmt.say pmsg("\n Release dependencies starting...\n")

    ## from release_infector
    when :multiple_gemspec
      v = args.first
      @pmt.select(pmsg("\n There are multiple gemspecs found. Please select one to proceed : "), filter: true) do |m|
        v.each do |vv|
          m.choice vv, vv
        end
      end

    when :adding_to_gemspec
      v = args.first
      @pmt.say pmsg("\n Adding release-gem to gemspec '#{v[:gemspec]}'")

    when :gemspec_updated
      v = args.first
      @pmt.say pmsg("\n Gemspec file of GEM '#{v[:name]}' updated with release-gem gem")
    
    when :gemspec_already_has_gem
      v = args.first
      @pmt.say pmsg("\n Gemspec file of GEM '#{v[:name]}' already has release-gem gem included. Skipped")

    when :adding_to_rackfile
      v = args.first
      @pmt.say pmsg("\n Adding require to Rakefile at #{v[:rakefile]}")

    when :creating_new_rakefile
      v = args.first
      @pmt.say pmsg("\n Creating new Rakefile at #{v[:rakefile]}")

    when :rakefile_updated
      v = args.first
      @pmt.say pmsg("\n Rakefile '#{v[:rakefile]}' updated!")

    when :select_terminal
      v = args.first
      @pmt.select(pmsg("\n Please select a terminal for development GEM '#{v[:name]}' release : "), filter: true) do |m|
        v[:options].each do |t|
          m.choice t, t
        end
        m.choice "Skip", :skip
      end

    when :new_terminal_launching
      v = args.first
      @pmt.say pmsg("\n New terminal lanching for GEM '#{v[:name]}' using terminal '#{v[:terminal]}'")

    when :new_terminal_launched
      v = args.first
      @pmt.say pmsg("\n New terminal launched for GEM '#{v[:name]}' using terminal '#{v[:terminal]}'")

    when :block_until_dev_gem_done
      v = args.first
      @pmt.yes? pmsg("\n Development GEM '#{v[:name]}' has separate windows for release. Is it done? ")

    ### End release_infector

    when :define_gem_prod_config

      config = {}
      selections = args.first[:gems].clone

      loop do

        sel = @pmt.select(pmsg("\n The following development gems requires configuration. Please select one to configure "), filter: true) do |m|
          selections.each do |key, val|
            m.choice key, key
          end
        end

        config[sel] = {} if config[sel].nil?

        type = @pmt.select(pmsg("\n The gem in production will be runtime or development ? ")) do |m|
          m.choice "Runtime", :runtime
          m.choice "Development only", :dev
        end

        config[sel][:type] = type

        gemAct = Action::GemAction.new(selections[sel])
        currentVersion = gemAct.find_gem_version do |ops, *val|
          case ops
          when :multiple_version_files_found
            # abort. Expected only 1 version files exist
          end
        end

        ver = @pmt.ask(pmsg("\n Is there specific version pattern (including the ~>/>/>=/= of gemspec) for the gem in production? (Not mandatory) : "), value: currentVersion)
        config[sel][:version] = ver if not_empty?(ver)

        @pmt.puts pmsg(" ** Done configure for gem #{sel}")
        selections.delete_if { |v| v == sel }
        break if selections.length == 0

      end

      config

    when :development_gem_temporary_promoted
      @pmt.puts pmsg("\n Development gem(s) temporary promoted to production status")

    when :no_development_gems_found
      @pmt.puts pmsg("\n No development gem(s) in used found")

    when :invalid_gem_prod_config
      @pmt.puts pastel.red(pmsg("\n #{args.first}"))

    end
  end

end