Sha256: fdaac9a5d1fa0ff32cfeeeddf9a54e2ed0bc938a017234d4138d0eb19499bebb

Contents?: true

Size: 1.15 KB

Versions: 41

Compression:

Stored size: 1.15 KB

Contents

require 'json'

module Bibliothecary
  module Parsers
    class Packagist
      include Bibliothecary::Analyser

      def self.mapping
        {
          match_filename("composer.json") => {
            kind: 'manifest',
            parser: :parse_manifest
          },
          match_filename("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

41 entries across 41 versions & 1 rubygems

Version Path
bibliothecary-7.0.2 lib/bibliothecary/parsers/packagist.rb
bibliothecary-7.0.1 lib/bibliothecary/parsers/packagist.rb
bibliothecary-7.0.0 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.12.3 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.12.2 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.12.1 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.12.0 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.11.0 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.10.7 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.10.6 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.10.5 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.10.4 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.10.3 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.10.2 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.10.1 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.9.8 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.9.7 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.9.6 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.9.5 lib/bibliothecary/parsers/packagist.rb
bibliothecary-6.9.4 lib/bibliothecary/parsers/packagist.rb