Sha256: 2fb705db41dcda7f2aacdb52022fcc9bcfa4dc0c2db9823dff9c8cbb5bee3923

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

require 'forwardable'

module LicenseFinder
  class PackageSaver
    extend Forwardable
    def_delegators :package, :licenses, :children, :groups, :summary, :description, :version, :homepage

    attr_reader :dependency, :package

    def self.save_all(packages)
      packages.map do |package|
        find_or_create_by_name(package).save
      end
    end

    def initialize(dependency, package)
      @dependency = dependency
      @package = package
    end

    def save
      dependency.version = version.to_s
      dependency.summary = summary
      dependency.description = description
      dependency.homepage = homepage
      dependency.bundler_group_names = groups.map(&:to_s)
      dependency.children_names = children
      dependency.set_licenses licenses

      # Only save *changed* dependencies. This ensures re-running
      # `license_finder` won't always update the DB, and therefore won't always
      # update the HTML/markdown reports with a new timestamp.
      dependency.save_changes
      dependency
    end

    private

    def self.find_or_create_by_name(package)
      dependency = Dependency.named(package.name)
      new(dependency, package)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
license_finder-1.2 lib/license_finder/package_saver.rb
license_finder-1.2-java lib/license_finder/package_saver.rb