Module: LicenseFinder::DependencyManager

Defined in:
lib/license_finder/dependency_manager.rb

Class Method Summary collapse

Class Method Details

.approve!(name) ⇒ Object



44
45
46
# File 'lib/license_finder/dependency_manager.rb', line 44

def self.approve!(name)
  modifying { find_by_name(name).approve!  }
end

.create_non_bundler(license, name, version) ⇒ Object

Raises:



25
26
27
28
29
30
31
32
33
34
# File 'lib/license_finder/dependency_manager.rb', line 25

def self.create_non_bundler(license, name, version)
  raise Error.new("#{name} dependency already exists") unless Dependency.where(name: name).empty?

  modifying {
    dependency = Dependency.new(manual: true, name: name, version: version)
    dependency.license = LicenseAlias.create(name: license)
    dependency.approval = Approval.create
    dependency.save
  }
end

.destroy_non_bundler(name) ⇒ Object



36
37
38
# File 'lib/license_finder/dependency_manager.rb', line 36

def self.destroy_non_bundler(name)
  modifying { find_by_name(name, Dependency.non_bundler).destroy }
end

.license!(name, license) ⇒ Object



40
41
42
# File 'lib/license_finder/dependency_manager.rb', line 40

def self.license!(name, license)
  modifying { find_by_name(name).set_license_manually!(license) }
end

.modifyingObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/license_finder/dependency_manager.rb', line 48

def self.modifying
  checksum_before_modifying = if File.exists? LicenseFinder.config.database_uri
                                Digest::SHA2.file(LicenseFinder.config.database_uri).hexdigest
                              end
  result = yield
  checksum_after_modifying = Digest::SHA2.file(LicenseFinder.config.database_uri).hexdigest

  unless checksum_after_modifying == checksum_before_modifying
    Reporter.write_reports
  end
  unless File.exists? LicenseFinder.config.dependencies_html
    Reporter.write_reports
  end

  result
end

.sync_with_bundlerObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/license_finder/dependency_manager.rb', line 5

def self.sync_with_bundler
  modifying {
    current_dependencies = []

    if Bundle.has_gemfile?
      current_dependencies += PackageSaver.save_packages(Bundle.current_gems(LicenseFinder.config))
    end

    if Pip.has_requirements?
      current_dependencies += PackageSaver.save_packages(Pip.current_dists())
    end

    if NPM.has_package?
      current_dependencies += PackageSaver.save_packages(NPM.current_modules())
    end

    Dependency.bundler.obsolete(current_dependencies).each(&:destroy)
  }
end