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.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bibliothecary/related_files_info.rb', line 32

def initialize(file_infos)
  package_manager = file_infos.first.package_manager
  ordered_file_infos = file_infos

  if package_manager.respond_to?(:lockfile_preference_order)
    ordered_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

  @manifests = filter_file_infos_by_package_manager_type(
    file_infos: ordered_file_infos,
    package_manager: package_manager,
    type: "manifest"
  )

  @lockfiles = filter_file_infos_by_package_manager_type(
    file_infos: ordered_file_infos,
    package_manager: package_manager,
    type: "lockfile"
  )
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

Create a set of RelatedFilesInfo for the provided file_infos, where each RelatedFilesInfo contains all the file_infos



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/bibliothecary/related_files_info.rb', line 10

def self.create_from_file_infos(file_infos)
  returns = []

  file_infos_by_directory = file_infos.group_by { |info| File.dirname(info.relative_path) }
  file_infos_by_directory.values.each do |file_infos_for_path|
    groupable, ungroupable = file_infos_for_path.partition(&:groupable?)

    # add ungroupable ones as separate RFIs
    ungroupable.each do |file_info|
      returns.append(RelatedFilesInfo.new([file_info]))
    end

    file_infos_by_directory_by_package_manager = groupable.group_by { |info| info.package_manager}

    file_infos_by_directory_by_package_manager.values.each do |file_infos_in_directory_for_package_manager|
      returns.append(RelatedFilesInfo.new(file_infos_in_directory_for_package_manager))
    end
  end

  returns
end