Sha256: 358df2f52c5072c192743fb5b06bfeced84e7a30bab67a3af488431373dc2c21

Contents?: true

Size: 1.12 KB

Versions: 9

Compression:

Stored size: 1.12 KB

Contents

require 'json'

module Bibliothecary
  module Parsers
    class Packagist
      include Bibliothecary::Analyser

      def self.mapping
        {
          /^composer\.json$/ => {
            kind: 'manifest',
            parser: :parse_manifest
          },
          /^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

9 entries across 9 versions & 1 rubygems

Version Path
bibliothecary-6.2.1 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.2.0 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.1.0 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.0.0 lib/bibliothecary/parsers/packagist.rb
bibliothecary-5.6.2 lib/bibliothecary/parsers/packagist.rb
bibliothecary-5.6.1 lib/bibliothecary/parsers/packagist.rb
bibliothecary-5.6.0 lib/bibliothecary/parsers/packagist.rb
bibliothecary-5.5.5 lib/bibliothecary/parsers/packagist.rb
bibliothecary-5.5.4 lib/bibliothecary/parsers/packagist.rb