Class: DRG::Tasks::Updater
- Inherits:
-
Object
- Object
- DRG::Tasks::Updater
- Includes:
- Log
- Defined in:
- lib/drg/tasks/updater.rb
Instance Attribute Summary collapse
-
#bundler ⇒ Object
readonly
Returns the value of attribute bundler.
-
#failures ⇒ Object
readonly
Returns the value of attribute failures.
-
#gemfile ⇒ Object
readonly
Returns the value of attribute gemfile.
Instance Method Summary collapse
-
#initialize ⇒ Updater
constructor
A new instance of Updater.
-
#perform(handler = method(:try_update)) ⇒ Object
Updates the projects outdated gems listed in the Gemfile.
- #try_update(gem) ⇒ Object
Methods included from Log
Constructor Details
Instance Attribute Details
#bundler ⇒ Object (readonly)
Returns the value of attribute bundler.
6 7 8 |
# File 'lib/drg/tasks/updater.rb', line 6 def bundler @bundler end |
#failures ⇒ Object (readonly)
Returns the value of attribute failures.
6 7 8 |
# File 'lib/drg/tasks/updater.rb', line 6 def failures @failures end |
#gemfile ⇒ Object (readonly)
Returns the value of attribute gemfile.
6 7 8 |
# File 'lib/drg/tasks/updater.rb', line 6 def gemfile @gemfile end |
Instance Method Details
#perform(handler = method(:try_update)) ⇒ Object
TODO:
Cleanup old gems when finished
Note:
‘bundle outdated` returns lines that look like ’slop (newest 4.2.0, installed 3.6.0) in group “default”‘
Updates the projects outdated gems listed in the Gemfile
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/drg/tasks/updater.rb', line 19 def perform(handler = method(:try_update)) log 'Searching for outdated gems ....' outdated = `bundle outdated`.scan(/\s\*\s(.+)\s/).flatten gems = outdated.map do |item| gem = OpenStruct.new gem.name = item[/([\-\w0-9]+)\s/, 1] gem.entry = gemfile.find_by_name(gem.name) next unless gem.entry gem.latest_version = item[/newest\s([\d.\w]+)/, 1] gem.current_version = item[/installed\s([\d.\w]+)/, 1] gem end.compact if gems.any? gems.each &handler else log 'All gems up to date!' end end |
#try_update(gem) ⇒ Object
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 |
# File 'lib/drg/tasks/updater.rb', line 39 def try_update(gem) log(%Q[Updating "#{gem.name}" from #{gem.current_version} to #{gem.latest_version}]) gemfile.remove_version gem.entry bundler.update(gem.name) if $0.to_i.zero? log(%Q[Succeeded in installing "#{gem.name}" (#{gem.latest_version})]) if system('rake') log(%Q[Tests passed! Updating Gemfile entry for "#{gem.name}" to #{gem.latest_version}]) gemfile.update(gem.entry, gem.latest_version) gemfile.write else failures << gem.name end else fail StandardError, %Q[Failed to update "#{gem.name}"] end rescue Bundler::GemNotFound, Bundler::InstallError, Bundler::VersionConflict => e # @todo retry it later log %Q[Failed to find a compatible of "#{gem.name}" (#{gem.latest_version}): #{e.class} #{e.}] gemfile.rollback failures << gem.name rescue => e puts "#{e.class}: #{e.} #{e.backtrace}" gemfile.rollback end |