Class: Rrm::Updater

Inherits:
Object
  • Object
show all
Defined in:
lib/rrm/updater.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Updater

Needs options as a hash. Options follow the naming from the console application in bin/rrm. Example

{ :urls => [

    [0] "[email protected]:kickban/form-kickban-fi.git"
],
  :patch_next => false,
  :patch_latest => true,
  :minor_next => false,
  :minor_latest => false,
  :major_next => false,
  :major_latest => false,
  :update_gems => false
}


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rrm/updater.rb', line 22

def initialize(options)
  $env_variables = options[:env]

  @options = options
  if options[:major_latest]
    @level = :major_latest
  elsif options[:major_next]
    @level = :major_next
  elsif options[:minor_latest]
    @level = :minor_latest
  elsif options[:minor_next]
    @level = :minor_next
  elsif options[:patch_latest]
    @level = :patch_latest
  elsif options[:patch_next]
    @level = :patch_next
  end
end

Instance Attribute Details

#levelObject

Returns the value of attribute level.



6
7
8
# File 'lib/rrm/updater.rb', line 6

def level
  @level
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/rrm/updater.rb', line 5

def options
  @options
end

Instance Method Details

#all_repositoriesObject



67
68
69
# File 'lib/rrm/updater.rb', line 67

def all_repositories
  @all_repositories ||=fetch_all_repositories
end

#update_allObject



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
# File 'lib/rrm/updater.rb', line 41

def update_all
  raise "Choose what to update" if @level.nil?

  Rrm.logger.debug "Available normal Ruby versions: #{Rrm.all_ruby_versions}"
  all_repositories.each do |repository|
    puts "#{repository.name} from #{repository.current_version} to #{repository.new_version}"
  end

  bar = TTY::ProgressBar.new("Running upgrades (:current of :total) [:bar]", total: all_repositories.size, width: 30)
  all_repositories.each do |repository|
    repository.update!
    bar.advance(1)
  end

  bar = TTY::ProgressBar.new("Pushing branches (:current of :total) [:bar]", total: all_repositories.size, width: 30)
  all_repositories.each do |repository|
    repository.push!
    bar.advance(1)
  end

  puts "Pushed branches:"
  all_repositories.each do |repository|
    puts "#{repository.branch_name} (#{repository.git.remote.url})"
  end
end