Last active
October 4, 2019 12:51
-
-
Save International/63fe97c0d80cc54eaa8755196a86f80d to your computer and use it in GitHub Desktop.
rubocop_installer.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lines = File.readlines('Gemfile.lock').grep(/rubocop/i) | |
pattern = /rubocop \((.*?)\)/ | |
act_rubocop = lines.find{ |e| e =~ pattern } | |
rubocop_version = act_rubocop[pattern, 1] | |
installed_ones = {} | |
abort("Failed to install rubocop: #{rubocop_version}") unless system("gem install rubocop -v #{rubocop_version}") | |
lines.reject{|e| e == act_rubocop}.reject{|e| e =~ /rubocop \(/}.select{|e| e.index('(')}.each do |other| | |
gem_name, version = other.split(/\s+/).reject(&:empty?) | |
version = version.sub('(','').sub(')','') | |
next if installed_ones.key?(gem_name) | |
gem_ver = "#{gem_name} -v #{version}" | |
puts "executing: #{gem_ver}" | |
abort("Failed to install: #{gem_ver}") unless system("gem install #{gem_ver}") | |
installed_ones[gem_name] = 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment