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.



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

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

  if parser.respond_to?(:lockfile_preference_order)
    ordered_file_infos = parser.lockfile_preference_order(file_infos)
  end

  @parser = parser.parser_name
  @path = Pathname.new(File.dirname(file_infos.first.relative_path)).cleanpath.to_path

  @manifests = filter_file_infos_by_parser_type(
    file_infos: ordered_file_infos,
    parser: parser,
    type: "manifest"
  )

  @lockfiles = filter_file_infos_by_parser_type(
    file_infos: ordered_file_infos,
    parser: parser,
    type: "lockfile"
  )
end

Instance Attribute Details

#lockfilesObject (readonly)

Returns the value of attribute lockfiles.



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

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

#parserObject (readonly)

Returns the value of attribute parser.



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

def parser
  @parser
end

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
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



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

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.each_value 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_parser = groupable.group_by(&:parser)

    file_infos_by_directory_by_parser.each_value do |file_infos_in_directory_for_parser|
      returns.append(RelatedFilesInfo.new(file_infos_in_directory_for_parser))
    end
  end

  returns
end

Instance Method Details

#platformObject



55
56
57
# File 'lib/bibliothecary/related_files_info.rb', line 55

def platform
  raise "Bibliothecary::RelatedFileInfo#platform() has been removed in bibliothecary 15.0.0. Use parser() instead, which now includes MultiParsers."
end