Class: LicenseFinder::PackageManager

Inherits:
Object
  • Object
show all
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

Direct Known Subclasses

Bower, Bundler, CocoaPods, Gradle, Maven, NPM, Pip, Rebar

Class Method Summary collapse

Instance Method Summary collapse

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 options={}
  @logger       = options[:logger] || Core.default_logger
  @project_path = options[: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(options)
  package_managers
    .map { |pm| pm.new(options) }
    .select(&:active?)
    .flat_map(&:current_packages_with_relations)
end

.package_managersObject



15
16
17
# File 'lib/license_finder/package_manager.rb', line 15

def self.package_managers
  [Bundler, NPM, Pip, Bower, Maven, Gradle, CocoaPods, Rebar]
end

Instance Method Details

#active?Boolean

Returns:

  • (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_relationsObject



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