Class: Bibliothecary::RelatedFilesInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/bibliothecary/related_files_info.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_infos) ⇒ RelatedFilesInfo

Returns a new instance of RelatedFilesInfo.



20
21
22
23
24
25
26
27
# File 'lib/bibliothecary/related_files_info.rb', line 20

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 { |info| File.basename(info.relative_path) }
  @lockfiles = file_infos.select { |info| package_manager.determine_kind_from_info(info).include? "lockfile" }.map { |info| File.basename(info.relative_path) }
end

Instance Attribute Details

#lockfilesObject (readonly)

Returns the value of attribute lockfiles.



6
7
8
# File 'lib/bibliothecary/related_files_info.rb', line 6

def lockfiles
  @lockfiles
end

#manifestsObject (readonly)

Returns the value of attribute manifests.



5
6
7
# File 'lib/bibliothecary/related_files_info.rb', line 5

def manifests
  @manifests
end

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/bibliothecary/related_files_info.rb', line 3

def path
  @path
end

#platformObject (readonly)

Returns the value of attribute platform.



4
5
6
# File 'lib/bibliothecary/related_files_info.rb', line 4

def platform
  @platform
end

Class Method Details

.create_from_file_infos(file_infos) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/bibliothecary/related_files_info.rb', line 8

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