Class: LicenseFinder::PackageManager
- Inherits:
-
Object
- Object
- LicenseFinder::PackageManager
- Defined in:
- lib/license_finder/package_manager.rb
Overview
Super-class for the different package managers (Bundler, NPM, Pip, etc.)
For guidance on adding a new package manager use the shared behavior
it_behaves_like "a PackageManager"
Additional guidelines are:
-
implement #current_packages, to return a list of ‘Package`s this package manager is tracking
-
implement #package_path, a ‘Pathname` which, if the file exists, indicates the package manager is in use on this project
Class Method Summary collapse
Instance Method Summary collapse
- #active? ⇒ Boolean
- #current_packages_with_relations ⇒ Object
-
#initialize(options = {}) ⇒ PackageManager
constructor
A new instance of PackageManager.
Constructor Details
#initialize(options = {}) ⇒ PackageManager
Returns a new instance of PackageManager.
26 27 28 29 |
# File 'lib/license_finder/package_manager.rb', line 26 def initialize ={} @logger = [:logger] || Core.default_logger @project_path = [:project_path] end |
Class Method Details
.current_packages(options) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/license_finder/package_manager.rb', line 19 def self.current_packages() package_managers .map { |pm| pm.new() } .select(&:active?) .flat_map(&:current_packages_with_relations) end |
Instance Method Details
#active? ⇒ Boolean
31 32 33 34 |
# File 'lib/license_finder/package_manager.rb', line 31 def active? package_path.exist? .tap { |is_active| logger.active self.class, is_active } end |
#current_packages_with_relations ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/license_finder/package_manager.rb', line 36 def current_packages_with_relations packages = current_packages packages.each do |parent| parent.children.each do |child_name| child = packages.detect { |child| child.name == child_name } child.parents << parent.name if child end end packages end |