Sha256: e4e3059c3487a3fcdf585e5820f0fbd039e32c53ac4d3bf47e6f292ed2635b5b

Contents?: true

Size: 1.75 KB

Versions: 4

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true
require "json"
require "pathname"
require "uri"

# **NOTE** Cocoapods is disabled until cocoapods-core supports recent rails versions
# https://github.com/CocoaPods/Core/pull/733
# require "cocoapods-core"

module Licensed
  module Sources
    class Cocoapods < Source
      def enabled?
        false

        # return unless Licensed::Shell.tool_available?("pod")

        # config.pwd.join("Podfile").exist? && config.pwd.join("Podfile.lock").exist?
      end

      def enumerate_dependencies
        pods.map do |pod|
          name = pod.name
          path = dependency_path(pod.root_name)
          version = lockfile.version(name).version

          Dependency.new(
            path: path,
            name: name,
            version: version,
            metadata: { "type" => Cocoapods.type }
          )
        end
      end

      private

      def pods
        return lockfile.dependencies if targets.nil?

        targets_to_validate = podfile.target_definition_list.filter { |t| targets.include?(t.label) }
        if targets_to_validate.any?
          targets_to_validate.map(&:dependencies).flatten
        else
          raise Licensed::Sources::Source::Error, "Unable to find any target in the Podfile matching the ones provided in the config."
        end
      end

      def targets
        @targets ||= config.dig("cocoapods", "targets")&.map { |t| "Pods-#{t}" }
      end

      def lockfile
        @lockfile = nil
        # @lockfile ||= Pod::Lockfile.from_file(config.pwd.join("Podfile.lock"))
      end

      def podfile
        @podfile = nil
        # @podfile ||= Pod::Podfile.from_file(config.pwd.join("Podfile"))
      end

      def dependency_path(name)
        config.pwd.join("Pods/#{name}")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
licensed-4.2.0 lib/licensed/sources/cocoapods.rb
licensed-4.1.0 lib/licensed/sources/cocoapods.rb
licensed-4.0.4 lib/licensed/sources/cocoapods.rb
licensed-4.0.3 lib/licensed/sources/cocoapods.rb