Class: Bundler::Multilock::Cache
- Inherits:
-
Object
- Object
- Bundler::Multilock::Cache
- Defined in:
- lib/bundler/multilock/cache.rb
Overview
caches lockfiles across multiple lockfile checks or sync runs
Instance Method Summary collapse
- #conflicting_requirements?(lockfile1_name, lockfile2_name, spec1, spec2) ⇒ Boolean
-
#contents(lockfile_name) ⇒ String
The raw contents of the lockfile.
-
#find_matching_spec(specs, spec) ⇒ Object
sometimes a gem changes platforms with a new version, such as from aarch64-linux to aarch64-linux-gnu.
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
- #invalidate_checks(lockfile_name) ⇒ Object
-
#invalidate_lockfile(lockfile_name) ⇒ void
Removes a given lockfile’s associated cached data.
- #log_missing_spec(spec) ⇒ Object
- #parser(lockfile_name) ⇒ LockfileParser
-
#reverse_dependencies(lockfile_name) ⇒ Hash<String, Set<String>>
Hash of gem name to set of gem names that depend on it.
-
#reverse_requirements(lockfile_name) ⇒ Hash<String, Gem::Requirement>
Hash of gem name to requirement for that gem.
- #specs(lockfile_name) ⇒ Object
Constructor Details
#initialize ⇒ Cache
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
95 96 97 98 99 100 101 |
# File 'lib/bundler/multilock/cache.rb', line 95 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.
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 |
#find_matching_spec(specs, spec) ⇒ Object
sometimes a gem changes platforms with a new version, such as from aarch64-linux to aarch64-linux-gnu. we need to still sync it
71 72 73 74 75 76 77 78 79 |
# File 'lib/bundler/multilock/cache.rb', line 71 def find_matching_spec(specs, spec) specs = self.specs(specs) unless specs.is_a?(Hash) platform_specs = specs[spec.name] return unless platform_specs parent_spec = platform_specs[spec.platform] parent_spec ||= platform_specs.find { |platform, _| platform =~ spec.platform }&.last parent_spec || platform_specs.find { |platform, _| platform == "ruby" }&.last 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
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
103 104 105 106 107 108 109 |
# File 'lib/bundler/multilock/cache.rb', line 103 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
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.
83 84 85 86 |
# File 'lib/bundler/multilock/cache.rb', line 83 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.
90 91 92 93 |
# File 'lib/bundler/multilock/cache.rb', line 90 def reverse_requirements(lockfile_name) ensure_reverse_data(lockfile_name) @reverse_requirements[lockfile_name] end |
#specs(lockfile_name) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/bundler/multilock/cache.rb', line 59 def specs(lockfile_name) @specs[lockfile_name] ||= begin specs = {} parser(lockfile_name).specs.each do |spec| (specs[spec.name] ||= {})[spec.platform] = spec end specs end end |