Module: Bibliothecary::MultiParsers::DependenciesCSV

Includes:
Analyser, Analyser::TryCache
Defined in:
lib/bibliothecary/multi_parsers/dependencies_csv.rb

Defined Under Namespace

Classes: CSVFile

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Analyser::TryCache

#try_cache

Methods included from Analyser

create_analysis, create_error_analysis, included

Class Method Details

.mappingObject



11
12
13
14
15
16
17
18
19
# File 'lib/bibliothecary/multi_parsers/dependencies_csv.rb', line 11

def self.mapping
  {
    match_filename("dependencies.csv") => {
      kind: "lockfile",
      ungroupable: true,
      parser: :parse_dependencies_csv,
    },
  }
end

Instance Method Details

#parse_dependencies_csv(file_contents, options: {}) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/bibliothecary/multi_parsers/dependencies_csv.rb', line 135

def parse_dependencies_csv(file_contents, options: {})
  csv_file = try_cache(options, options[:filename]) do
    raw_csv_file = CSVFile.new(file_contents)
    raw_csv_file.parse!
    raw_csv_file
  end

  dependencies = csv_file
    .result
    .find_all { |dependency| dependency[:platform] == platform_name.to_s }
    .map do |dep_kvs|
      Dependency.new(
        **dep_kvs, source: options.fetch(:filename, nil)
      )
    end

  ParserResult.new(dependencies: dependencies)
end