Sha256: 10557d796c914bd969c2f272a75314c73ed3c8bfcbc3b675218510503631fd53

Contents?: true

Size: 1.88 KB

Versions: 56

Compression:

Stored size: 1.88 KB

Contents

require 'gemnasium/parser'
require 'yaml'

module Bibliothecary
  module Parsers
    class CocoaPods
      include Bibliothecary::Analyser

      NAME_VERSION = '(?! )(.*?)(?: \(([^-]*)(?:-(.*))?\))?'.freeze
      NAME_VERSION_4 = /^ {4}#{NAME_VERSION}$/

      def self.mapping
        {
          match_filename("Podfile") => {
            kind: 'manifest',
            parser: :parse_podfile
          },
          match_extension(".podspec") => {
            kind: 'manifest',
            parser: :parse_podspec,
            can_have_lockfile: false
          },
          match_filename("Podfile.lock") => {
            kind: 'lockfile',
            parser: :parse_podfile_lock
          },
          match_extension(".podspec.json") => {
            kind: 'manifest',
            parser: :parse_json_manifest,
            can_have_lockfile: false
          }
        }
      end

      def self.parse_podfile_lock(file_contents)
        manifest = YAML.load file_contents
        manifest['PODS'].map do |row|
          pod = row.is_a?(String) ? row : row.keys.first
          match = pod.match(/(.+?)\s\((.+?)\)/i)
          {
            name: match[1].split('/').first,
            requirement: match[2],
            type: 'runtime'
          }
        end.compact
      end

      def self.parse_podspec(file_contents)
        manifest = Gemnasium::Parser.send(:podspec, file_contents)
        parse_ruby_manifest(manifest)
      end

      def self.parse_podfile(file_contents)
        manifest = Gemnasium::Parser.send(:podfile, file_contents)
        parse_ruby_manifest(manifest)
      end

      def self.parse_json_manifest(file_contents)
        manifest = JSON.parse(file_contents)
        manifest['dependencies'].inject([]) do |deps, dep|
          deps.push({
            name: dep[0],
            requirement: dep[1],
            type: 'runtime'
          })
        end.uniq
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
bibliothecary-6.12.1 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.12.0 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.11.0 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.10.7 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.10.6 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.10.5 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.10.4 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.10.3 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.10.2 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.10.1 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.9.8 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.9.7 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.9.6 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.9.5 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.9.4 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.9.3 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.9.2 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.9.1 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.9.0 lib/bibliothecary/parsers/cocoapods.rb
bibliothecary-6.8.10 lib/bibliothecary/parsers/cocoapods.rb