Sha256: 01fdd92ce5cd13c51ee0919fdf4a248ae8b19becd41829c2b4c9269dd6193298

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require 'json'

module Bibliothecary
  module Parsers
    class Packagist
      include Bibliothecary::Analyser

      def self.mapping
        {
          /^composer\.json$|.*\/composer\.json$/ => {
            kind: 'manifest',
            parser: :parse_manifest
          },
          /^composer\.lock$|.*\/composer\.lock$/ => {
            kind: 'lockfile',
            parser: :parse_lockfile
          }
        }
      end

      def self.parse_lockfile(file_contents)
        manifest = JSON.parse file_contents
        manifest.fetch('packages',[]).map do |dependency|
          {
            name: dependency["name"],
            requirement: dependency["version"],
            type: 'runtime'
          }
        end + manifest.fetch('packages-dev',[]).map do |dependency|
          {
            name: dependency["name"],
            requirement: dependency["version"],
            type: 'development'
          }
        end
      end

      def self.parse_manifest(file_contents)
        manifest = JSON.parse file_contents
        map_dependencies(manifest, 'require', 'runtime') +
        map_dependencies(manifest, 'require-dev', 'development')
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bibliothecary-6.3.2 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.3.1 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.3.0 lib/bibliothecary/parsers/packagist.rb