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

Returns a new instance of GemFile.



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`.

Returns:

  • (Hash)

    gems for which there are differences.



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|
    updated_gem = new_spec_set.find { |new_gem| new_gem.name == old_gem.name }

    if updated_gem && old_gem.version != updated_gem.version
      fill_changes(old_gem, updated_gem)
    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