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.
-
#path_sourced_gem_names ⇒ Array<String>
private
Names of gems sourced from a local path, i.e.
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.
77 78 79 |
# File 'lib/rubocop/lockfile.rb', line 77 def includes_gem?(name) gems.any? { |gem| gem.name == name } end |
#path_sourced_gem_names ⇒ Array<String>
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.
Names of gems sourced from a local path, i.e. path: dependencies and the
project's own gem when the Gemfile uses gemspec. Git sources are not
included: their code lives outside the project, like a released gem's.
66 67 68 69 70 71 72 |
# File 'lib/rubocop/lockfile.rb', line 66 def path_sourced_gem_names return [] unless parser parser.specs.filter_map do |spec| spec.name if path_source?(spec.source) end end |