Class: StrongVersions::Dependencies

Inherits:
Object
  • Object
show all
Defined in:
lib/strong_versions/dependencies.rb

Instance Method Summary collapse

Constructor Details

#initialize(dependencies) ⇒ Dependencies

Returns a new instance of Dependencies.



5
6
7
8
9
10
11
# File 'lib/strong_versions/dependencies.rb', line 5

def initialize(dependencies)
  @dependencies = dependencies.map do |raw_dependency|
    Dependency.new(raw_dependency)
  end
  @invalid_gems = []
  @terminal = Terminal.new
end

Instance Method Details

#validate(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/strong_versions/dependencies.rb', line 27

def validate(options = {})
  unsafe_autocorrect_error if options[:auto_correct]
  @dependencies.each do |dependency|
    next if options.fetch(:except, []).include?(dependency.name)
    next if dependency.valid?

    @invalid_gems.push(dependency) unless dependency.valid?
  end
  @invalid_gems.empty?
end

#validate!(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/strong_versions/dependencies.rb', line 13

def validate!(options = {})
  auto_correct = options.delete(:auto_correct) { false }
  if validate(options)
    summary
    return true
  end

  return update_gemfile if auto_correct

  raise_or_warn(options.fetch(:on_failure, 'raise'))
  summary
  false
end