Class: GemUpdater::GemFile

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_updater/gem_file.rb

Overview

GemFile is responsible for handling `Gemfile`

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGemFile


10
11
12
# File 'lib/gem_updater/gem_file.rb', line 10

def initialize
  @changes = {}
end

Instance Attribute Details

#changesObject

Returns the value of attribute changes


7
8
9
# File 'lib/gem_updater/gem_file.rb', line 7

def changes
  @changes
end

#new_spec_setObject (readonly)

Returns the value of attribute new_spec_set


8
9
10
# File 'lib/gem_updater/gem_file.rb', line 8

def new_spec_set
  @new_spec_set
end

#old_spec_setObject (readonly)

Returns the value of attribute old_spec_set


8
9
10
# File 'lib/gem_updater/gem_file.rb', line 8

def old_spec_set
  @old_spec_set
end

Instance Method Details

#compute_changesHash

Compute the diffs between two `Gemfile.lock`.


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gem_updater/gem_file.rb', line 23

def compute_changes
  get_spec_sets

  old_spec_set.each do |old_gem|
    if updated_gem = new_spec_set.find{ |new_gem| new_gem.name == old_gem.name }
      unless old_gem.version == updated_gem.version
        changes[ old_gem.name ] = { versions: { old: old_gem.version.to_s, new: updated_gem.version.to_s }, source: updated_gem.source }
      end
    end
  end
end

#update!(gems) ⇒ Object

Run `bundle update` to update gems.


15
16
17
18
# File 'lib/gem_updater/gem_file.rb', line 15

def update!( gems )
  Bundler.ui.warn "Updating gems..."
  Bundler::CLI.start( [ 'update' ] + gems )
end