Class: Bundler::Multilock::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/multilock/cache.rb

Overview

caches lockfiles across multiple lockfile checks or sync runs

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/bundler/multilock/cache.rb', line 9

def initialize
  @contents = {}
  @parsers = {}
  @specs = {}
  @reverse_dependencies = {}
  @reverse_requirements = {}
  @base_checks = {}
  @deep_checks = {}
  @base_check_messages = {}
  @deep_check_messages = {}
  @missing_specs = Set.new
  @logged_missing = false
end

Instance Method Details

#conflicting_requirements?(lockfile1_name, lockfile2_name, spec1, spec2) ⇒ Boolean

Returns:

  • (Boolean)


79
80
81
82
83
84
85
# File 'lib/bundler/multilock/cache.rb', line 79

def conflicting_requirements?(lockfile1_name, lockfile2_name, spec1, spec2)
  reverse_requirements1 = reverse_requirements(lockfile1_name)[spec1.name]
  reverse_requirements2 = reverse_requirements(lockfile2_name)[spec1.name]

  !reverse_requirements1.satisfied_by?(spec2.version) &&
    !reverse_requirements2.satisfied_by?(spec1.version)
end

#contents(lockfile_name) ⇒ String

Returns the raw contents of the lockfile.

Parameters:

  • lockfile_name (Pathname)

Returns:

  • (String)

    the raw contents of the lockfile



47
48
49
50
51
# File 'lib/bundler/multilock/cache.rb', line 47

def contents(lockfile_name)
  @contents.fetch(lockfile_name) do
    @contents[lockfile_name] = lockfile_name.file? && lockfile_name.read.freeze
  end
end

#invalidate_checks(lockfile_name) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/bundler/multilock/cache.rb', line 37

def invalidate_checks(lockfile_name)
  @base_checks.delete(lockfile_name)
  @base_check_messages.delete(lockfile_name)
  # must clear them all; downstream lockfiles may depend on the state of this lockfile
  @deep_checks.clear
  @deep_check_messages.clear
end

#invalidate_lockfile(lockfile_name) ⇒ void

This method returns an undefined value.

Removes a given lockfile’s associated cached data

Should be called if the lockfile is modified

Parameters:

  • lockfile_name (Pathname)


28
29
30
31
32
33
34
35
# File 'lib/bundler/multilock/cache.rb', line 28

def invalidate_lockfile(lockfile_name)
  @contents.delete(lockfile_name)
  @parsers.delete(lockfile_name)
  @specs.delete(lockfile_name)
  @reverse_dependencies.delete(lockfile_name)
  @reverse_requirements.delete(lockfile_name)
  invalidate_checks(lockfile_name)
end

#log_missing_spec(spec) ⇒ Object



87
88
89
90
91
92
93
# File 'lib/bundler/multilock/cache.rb', line 87

def log_missing_spec(spec)
  return if @missing_specs.include?(spec)

  Bundler.ui.error "The following gems are missing" if @missing_specs.empty?
  @missing_specs << spec
  Bundler.ui.error(" * #{spec.name} (#{spec.version})")
end

#parser(lockfile_name) ⇒ LockfileParser

Parameters:

  • lockfile_name (Pathname)

Returns:

  • (LockfileParser)


55
56
57
# File 'lib/bundler/multilock/cache.rb', line 55

def parser(lockfile_name)
  @parsers[lockfile_name] ||= LockfileParser.new(contents(lockfile_name))
end

#reverse_dependencies(lockfile_name) ⇒ Hash<String, Set<String>>

Returns hash of gem name to set of gem names that depend on it.

Parameters:

  • lockfile_name (Pathname)

Returns:

  • (Hash<String, Set<String>>)

    hash of gem name to set of gem names that depend on it



67
68
69
70
# File 'lib/bundler/multilock/cache.rb', line 67

def reverse_dependencies(lockfile_name)
  ensure_reverse_data(lockfile_name)
  @reverse_dependencies[lockfile_name]
end

#reverse_requirements(lockfile_name) ⇒ Hash<String, Gem::Requirement>

Returns hash of gem name to requirement for that gem.

Parameters:

  • lockfile_name (Pathname)

Returns:

  • (Hash<String, Gem::Requirement>)

    hash of gem name to requirement for that gem



74
75
76
77
# File 'lib/bundler/multilock/cache.rb', line 74

def reverse_requirements(lockfile_name)
  ensure_reverse_data(lockfile_name)
  @reverse_requirements[lockfile_name]
end

#specs(lockfile_name) ⇒ Object



59
60
61
62
63
# File 'lib/bundler/multilock/cache.rb', line 59

def specs(lockfile_name)
  @specs[lockfile_name] ||= parser(lockfile_name).specs.to_h do |spec|
    [[spec.name, spec.platform], spec]
  end
end