Class: RuboCop::Lockfile Private
- Inherits:
-
Object
- Object
- RuboCop::Lockfile
- Defined in:
- lib/rubocop/lockfile.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Encapsulation of a lockfile for use when checking for gems. Does not actually resolve gems, just parses the lockfile.
Instance Method Summary collapse
-
#dependencies ⇒ Array<Bundler::Dependency>?
private
Gems that the bundle directly depends on.
-
#gem_versions(include_transitive_dependencies: true) ⇒ Object
private
Returns the locked versions of gems from this lockfile.
-
#gems ⇒ Array<Bundler::Dependency>?
private
All activated gems, including transitive dependencies.
-
#includes_gem?(name) ⇒ Boolean
private
Whether this lockfile includes the named gem, directly or indirectly.
-
#initialize(lockfile_path = nil) ⇒ Lockfile
constructor
private
A new instance of Lockfile.
Constructor Details
#initialize(lockfile_path = nil) ⇒ Lockfile
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Lockfile.
17 18 19 20 21 22 23 24 25 |
# File 'lib/rubocop/lockfile.rb', line 17 def initialize(lockfile_path = nil) lockfile_path ||= begin ::Bundler.default_lockfile if use_bundler_lock_parser? rescue ::Bundler::GemfileNotFound nil # We might not be a folder with a Gemfile, but that's okay. end @lockfile_path = lockfile_path end |
Instance Method Details
#dependencies ⇒ Array<Bundler::Dependency>?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Gems that the bundle directly depends on.
29 30 31 32 33 |
# File 'lib/rubocop/lockfile.rb', line 29 def dependencies return [] unless parser parser.dependencies.values end |
#gem_versions(include_transitive_dependencies: true) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the locked versions of gems from this lockfile.
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rubocop/lockfile.rb', line 49 def gem_versions(include_transitive_dependencies: true) return {} unless parser all_gem_versions = parser.specs.to_h { |spec| [spec.name, spec.version] } if include_transitive_dependencies all_gem_versions else direct_dep_names = parser.dependencies.keys all_gem_versions.slice(*direct_dep_names) end end |
#gems ⇒ Array<Bundler::Dependency>?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
All activated gems, including transitive dependencies.
37 38 39 40 41 42 43 |
# File 'lib/rubocop/lockfile.rb', line 37 def gems return [] unless parser # `Bundler::LockfileParser` returns `Bundler::LazySpecification` objects # which are not resolved, so extract the dependencies from them parser.dependencies.values.concat(parser.specs.flat_map(&:dependencies)) end |
#includes_gem?(name) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whether this lockfile includes the named gem, directly or indirectly.
65 66 67 |
# File 'lib/rubocop/lockfile.rb', line 65 def includes_gem?(name) gems.any? { |gem| gem.name == name } end |