Class: Bibliothecary::Parsers::Packagist
- Inherits:
-
Object
- Object
- Bibliothecary::Parsers::Packagist
- Includes:
- Analyser
- Defined in:
- lib/bibliothecary/parsers/packagist.rb
Class Method Summary collapse
- .mapping ⇒ Object
- .parse_lockfile(file_contents, options: {}) ⇒ Object
- .parse_manifest(file_contents, options: {}) ⇒ Object
Methods included from Analyser
create_analysis, create_error_analysis, included
Class Method Details
.mapping ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/bibliothecary/parsers/packagist.rb', line 10 def self.mapping { match_filename("composer.json") => { kind: "manifest", parser: :parse_manifest, }, match_filename("composer.lock") => { kind: "lockfile", parser: :parse_lockfile, }, } end |
.parse_lockfile(file_contents, options: {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/bibliothecary/parsers/packagist.rb', line 27 def self.parse_lockfile(file_contents, options: {}) manifest = JSON.parse file_contents dependencies = manifest.fetch("packages", []).map do |dependency| requirement = dependency["version"] # Store Drupal version if Drupal, but include the original manifest version for reference if drupal_module?(dependency) original_requirement = requirement requirement = dependency.dig("source", "reference") end Dependency.new( name: dependency["name"], requirement: requirement, type: "runtime", original_requirement: original_requirement, source: .fetch(:filename, nil), platform: platform_name ) end + manifest.fetch("packages-dev", []).map do |dependency| requirement = dependency["version"] # Store Drupal version if Drupal, but include the original manifest version for reference if drupal_module?(dependency) original_requirement = requirement requirement = dependency.dig("source", "reference") end Dependency.new( name: dependency["name"], requirement: requirement, type: "development", original_requirement: original_requirement, source: .fetch(:filename, nil), platform: platform_name ) end ParserResult.new(dependencies: dependencies) end |
.parse_manifest(file_contents, options: {}) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/bibliothecary/parsers/packagist.rb', line 67 def self.parse_manifest(file_contents, options: {}) manifest = JSON.parse file_contents dependencies = map_dependencies(manifest, "require", "runtime", .fetch(:filename, nil)) + map_dependencies(manifest, "require-dev", "development", .fetch(:filename, nil)) ParserResult.new(dependencies: dependencies) end |