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:, version_control:, filter: NullFilter.new, out: $stdout) ⇒ Updater

Returns a new instance of Updater.



10
11
12
13
14
15
# File 'lib/keep_up/updater.rb', line 10

def initialize(bundle:, version_control:, filter: NullFilter.new, out: $stdout)
  @bundle = bundle
  @version_control = version_control
  @filter = filter
  @out = out
end

Instance Attribute Details

#bundleObject (readonly)

Returns the value of attribute bundle.



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

def bundle
  @bundle
end

#filterObject (readonly)

Returns the value of attribute filter.



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

def filter
  @filter
end

#version_controlObject (readonly)

Returns the value of attribute version_control.



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

def version_control
  @version_control
end

Instance Method Details

#possible_updatesObject



28
29
30
31
32
# File 'lib/keep_up/updater.rb', line 28

def possible_updates
  bundle.dependencies
    .select { |dep| filter.call dep }
    .select { |dep| updateable_dependency? dep }.uniq
end

#runObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/keep_up/updater.rb', line 17

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