class DependencyUpdater::GemHandler
Constants
- UPDATE_REGEX
captures Using|Installing, gem name, new version, old version
Public Class Methods
new(git_object)
click to toggle source
# File lib/dependency_updater/handlers/gem_handler.rb, line 11 def initialize(git_object) @gitlab = git_object @gems = [] @updated_capistrano = nil end
Public Instance Methods
update_capistrano_deploy()
click to toggle source
# File lib/dependency_updater/handlers/gem_handler.rb, line 29 def update_capistrano_deploy return unless check_for_capistrano actions = actions_from_filepath('config/deploy.rb') @gitlab.commit('Update deploy.rb with new Capistrano version', actions) end
update_gems()
click to toggle source
# File lib/dependency_updater/handlers/gem_handler.rb, line 17 def update_gems cmd = 'bundle update' output, err, status = Open3.capture3 cmd @gems = updated_gems output return false unless @gems.present? actions = actions_from_filepath('Gemfile.lock') @gitlab.commit("Update gems", actions) return true end
Private Instance Methods
actions_from_filepath(filepath)
click to toggle source
# File lib/dependency_updater/handlers/gem_handler.rb, line 48 def actions_from_filepath(filepath) actions = [] content = case filepath when 'config/deploy.rb' then new_deploy_file_text(filepath) when 'Gemfile.lock' then File.read(filepath).strip end actions << @gitlab.build_commit_action(filepath, content) end
check_for_capistrano()
click to toggle source
# File lib/dependency_updater/handlers/gem_handler.rb, line 58 def check_for_capistrano @updated_capistrano = @gems.select { |gem| gem[:name] == 'capistrano' }.first end
new_deploy_file_text(filepath)
click to toggle source
# File lib/dependency_updater/handlers/gem_handler.rb, line 62 def new_deploy_file_text(filepath) File.read(filepath).strip.gsub(/lock '\d+?\.\d+?\.\d+?'/, "lock '#{@updated_capistrano[:new_version]}'") end
updated_gems(output)
click to toggle source
# File lib/dependency_updater/handlers/gem_handler.rb, line 38 def updated_gems output output.scan(UPDATE_REGEX).map do |match| { name: match[1], old_version: match[3], new_version: match[2] } end end