Class: KeepUp::Updater

Inherits:
Object
  • Object
show all
Defined in:
lib/keep_up/updater.rb

Overview

Apply potential updates to a Gemfile.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bundle:, repository:, version_control:, filter: NullFilter.new) ⇒ Updater

Returns a new instance of Updater.



8
9
10
11
12
13
# File 'lib/keep_up/updater.rb', line 8

def initialize(bundle:, repository:, version_control:, filter: NullFilter.new)
  @bundle = bundle
  @repository = repository
  @version_control = version_control
  @filter = filter
end

Instance Attribute Details

#bundleObject (readonly)

Returns the value of attribute bundle.



6
7
8
# File 'lib/keep_up/updater.rb', line 6

def bundle
  @bundle
end

#filterObject (readonly)

Returns the value of attribute filter.



6
7
8
# File 'lib/keep_up/updater.rb', line 6

def filter
  @filter
end

#repositoryObject (readonly)

Returns the value of attribute repository.



6
7
8
# File 'lib/keep_up/updater.rb', line 6

def repository
  @repository
end

#version_controlObject (readonly)

Returns the value of attribute version_control.



6
7
8
# File 'lib/keep_up/updater.rb', line 6

def version_control
  @version_control
end

Instance Method Details

#possible_updatesObject



25
26
27
28
29
# File 'lib/keep_up/updater.rb', line 25

def possible_updates
  bundle.direct_dependencies.
    select { |dep| filter.call dep }.
    map { |dep| repository.updated_dependency_for dep }.compact
end

#runObject



15
16
17
18
19
20
21
22
23
# File 'lib/keep_up/updater.rb', line 15

def run
  possible_updates.each do |update|
    if bundle.apply_updated_dependency update
      version_control.commit_changes update
    else
      version_control.revert_changes
    end
  end
end