Class: RBS::Collection::Config::LockfileGenerator
- Inherits:
-
Object
- Object
- RBS::Collection::Config::LockfileGenerator
- Defined in:
- lib/rbs/collection/config/lockfile_generator.rb
Defined Under Namespace
Classes: GemfileLockMismatchError
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
-
#existing_lockfile ⇒ Object
readonly
Returns the value of attribute existing_lockfile.
-
#gem_hash ⇒ Object
readonly
Returns the value of attribute gem_hash.
-
#lockfile ⇒ Object
readonly
Returns the value of attribute lockfile.
Class Method Summary collapse
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(config:, definition:, with_lockfile:) ⇒ LockfileGenerator
constructor
A new instance of LockfileGenerator.
Constructor Details
#initialize(config:, definition:, with_lockfile:) ⇒ LockfileGenerator
Returns a new instance of LockfileGenerator.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rbs/collection/config/lockfile_generator.rb', line 31 def initialize(config:, definition:, with_lockfile:) @config = config lockfile_path = Config.to_lockfile_path(config.config_path) lockfile_dir = lockfile_path.parent @lockfile = Lockfile.new( lockfile_path: lockfile_path, path: config.repo_path_data, gemfile_lock_path: definition.lockfile.relative_path_from(lockfile_dir) ) config.sources.each do |source| case source when Sources::Git lockfile.sources[source.name] = source end end if with_lockfile && lockfile_path.file? @existing_lockfile = Lockfile.from_lockfile(lockfile_path: lockfile_path, data: YAML.load_file(lockfile_path.to_s)) validate_gemfile_lock_path!(lock: @existing_lockfile, gemfile_lock_path: definition.lockfile) end @definition = definition @gem_hash = definition.locked_gems.specs.each.with_object({}) do |spec, hash| #$ Hash[String, Bundler::LazySpecification] hash[spec.name] = spec end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
23 24 25 |
# File 'lib/rbs/collection/config/lockfile_generator.rb', line 23 def config @config end |
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
23 24 25 |
# File 'lib/rbs/collection/config/lockfile_generator.rb', line 23 def definition @definition end |
#existing_lockfile ⇒ Object (readonly)
Returns the value of attribute existing_lockfile.
23 24 25 |
# File 'lib/rbs/collection/config/lockfile_generator.rb', line 23 def existing_lockfile @existing_lockfile end |
#gem_hash ⇒ Object (readonly)
Returns the value of attribute gem_hash.
23 24 25 |
# File 'lib/rbs/collection/config/lockfile_generator.rb', line 23 def gem_hash @gem_hash end |
#lockfile ⇒ Object (readonly)
Returns the value of attribute lockfile.
23 24 25 |
# File 'lib/rbs/collection/config/lockfile_generator.rb', line 23 def lockfile @lockfile end |
Class Method Details
.generate(config:, definition:, with_lockfile: true) ⇒ Object
25 26 27 28 29 |
# File 'lib/rbs/collection/config/lockfile_generator.rb', line 25 def self.generate(config:, definition:, with_lockfile: true) generator = new(config: config, definition: definition, with_lockfile: with_lockfile) generator.generate generator.lockfile end |
Instance Method Details
#generate ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/rbs/collection/config/lockfile_generator.rb', line 60 def generate ignored_gems = config.gems.select {|gem| gem["ignore"] }.map {|gem| gem["name"] }.to_set config.gems.each do |gem| if Sources::Stdlib.instance.has?(gem["name"], nil) || gem.dig("source", "type") == "stdlib" unless ignored_gems.include?(gem["name"]) assign_stdlib(name: gem["name"], from_gem: nil) end else assign_gem(name: gem["name"], version: gem["version"], ignored_gems: ignored_gems, src_data: gem["source"]) end end definition.dependencies.each do |dep| if dep.autorequire && dep.autorequire.empty? next end spec = gem_hash[dep.name] or raise "Cannot find `#{dep.name}` in bundler context" assign_gem(name: dep.name, version: spec.version, ignored_gems: ignored_gems, src_data: nil) end lockfile.lockfile_path.write(YAML.dump(lockfile.to_lockfile)) end |