Class: GemUpdater::Gemfile

Inherits:
Object
  • Object
show all
Defined in:
lib/gem_updater/gemfile.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.



12
13
14
# File 'lib/gem_updater/gemfile.rb', line 12

def initialize
  @changes = {}
end

Instance Attribute Details

#changesObject

Returns the value of attribute changes.



9
10
11
# File 'lib/gem_updater/gemfile.rb', line 9

def changes
  @changes
end

#new_spec_setObject (readonly)

Returns the value of attribute new_spec_set.



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

def new_spec_set
  @new_spec_set
end

#old_spec_setObject (readonly)

Returns the value of attribute old_spec_set.



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

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.



25
26
27
28
29
30
31
32
33
34
# File 'lib/gem_updater/gemfile.rb', line 25

def compute_changes
  spec_sets_diff!

  old_spec_set.each do |old_gem|
    updated_gem = new_spec_set.find { |new_gem| new_gem.name == old_gem.name }
    next unless updated_gem && old_gem.version != updated_gem.version

    fill_changes(old_gem, updated_gem)
  end
end

#update!(gems) ⇒ Object

Run ‘bundle update` to update gems.



17
18
19
20
# File 'lib/gem_updater/gemfile.rb', line 17

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