Sha256: f438bc58e42e9d0f21efb12f8478007afa330d64c36834e87cc4e8b79c195545

Contents?: true

Size: 1.28 KB

Versions: 10

Compression:

Stored size: 1.28 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
      if package_manager.respond_to?(:lockfile_preference_order)
        file_infos = package_manager.lockfile_preference_order(file_infos)
      end
      @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

10 entries across 10 versions & 1 rubygems

Version Path
bibliothecary-8.2.1 lib/bibliothecary/related_files_info.rb
bibliothecary-8.2.0 lib/bibliothecary/related_files_info.rb
bibliothecary-8.1.1 lib/bibliothecary/related_files_info.rb
bibliothecary-8.1.0 lib/bibliothecary/related_files_info.rb
bibliothecary-8.0.0 lib/bibliothecary/related_files_info.rb
bibliothecary-7.3.6 lib/bibliothecary/related_files_info.rb
bibliothecary-7.3.5 lib/bibliothecary/related_files_info.rb
bibliothecary-7.3.4 lib/bibliothecary/related_files_info.rb
bibliothecary-7.3.3 lib/bibliothecary/related_files_info.rb
bibliothecary-7.3.2 lib/bibliothecary/related_files_info.rb