Sha256: 67361b182fce3fece01305e4cc2605eba68880e31e3af0530d36733bc3e4a24b

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

module Bibliothecary
  class RelatedFilesInfo
    attr_reader :path
    attr_reader :platform
    attr_reader :manifests
    attr_reader :lockfiles

    def self.create_from_file_infos(file_infos)
      returns = []
      paths = file_infos.group_by { |info| File.dirname(info.relative_path) }
      paths.values.each do |path|
        same_pm = path.group_by { |info| info.package_manager}
        same_pm.values.each do |value|
          returns.append(RelatedFilesInfo.new(value))
        end
      end
      returns
    end

    def initialize(file_infos)
      package_manager = file_infos.first.package_manager
      @platform = package_manager.platform_name
      @path = Pathname.new(File.dirname(file_infos.first.relative_path)).cleanpath.to_path
      # `package_manager.determine_kind_from_info(info)` can be an Array, so use include? which also works for string
      @manifests = file_infos.select { |info| package_manager.determine_kind_from_info(info).include? "manifest" }.map(&:relative_path)
      @lockfiles = file_infos.select { |info| package_manager.determine_kind_from_info(info).include? "lockfile" }.map(&:relative_path)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
bibliothecary-7.3.1 lib/bibliothecary/related_files_info.rb
bibliothecary-7.3.0 lib/bibliothecary/related_files_info.rb
bibliothecary-7.2.1 lib/bibliothecary/related_files_info.rb
bibliothecary-7.2.0 lib/bibliothecary/related_files_info.rb