Class: BundleUpdateInteractive::Lockfile
- Inherits:
-
Object
- Object
- BundleUpdateInteractive::Lockfile
- Defined in:
- lib/bundle_update_interactive/lockfile.rb
Class Method Summary collapse
-
.parse(lockfile_contents = File.read("Gemfile.lock")) ⇒ Object
TODO: refactor.
Instance Method Summary collapse
- #[](gem_name) ⇒ Object
- #entries ⇒ Object
-
#initialize(entries) ⇒ Lockfile
constructor
A new instance of Lockfile.
Constructor Details
#initialize(entries) ⇒ Lockfile
Returns a new instance of Lockfile.
42 43 44 |
# File 'lib/bundle_update_interactive/lockfile.rb', line 42 def initialize(entries) @entries = entries.freeze end |
Class Method Details
.parse(lockfile_contents = File.read("Gemfile.lock")) ⇒ Object
TODO: refactor
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bundle_update_interactive/lockfile.rb', line 8 def self.parse(lockfile_contents=File.read("Gemfile.lock")) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity parser = Bundler::LockfileParser.new(lockfile_contents) specs_by_name = {} exact = Set.new exact_children = {} parser.specs.each do |spec| specs_by_name[spec.name] = spec spec.dependencies.each do |dep| next unless dep.requirement.exact? exact << dep.name (exact_children[spec.name] ||= []) << dep.name end end entries = specs_by_name.transform_values do |spec| exact_dependencies = Set.new traversal = exact_children[spec.name]&.dup || [] until traversal.empty? name = traversal.pop next if exact_dependencies.include?(name) exact_dependencies << name traversal.push(*exact_children.fetch(name, [])) end LockfileEntry.new(spec, exact_dependencies, exact.include?(spec.name)) end new(entries) end |
Instance Method Details
#[](gem_name) ⇒ Object
50 51 52 |
# File 'lib/bundle_update_interactive/lockfile.rb', line 50 def [](gem_name) @entries[gem_name] end |
#entries ⇒ Object
46 47 48 |
# File 'lib/bundle_update_interactive/lockfile.rb', line 46 def entries @entries.values end |