class CocoapodsProtectedPrivate::Configuration

Attributes

config[RW]
config_loaded[RW]

Public Class Methods

new() click to toggle source
# File lib/cocoapods-protected-dependencies/config.rb, line 14
def initialize()
    load_configuration()
end

Public Instance Methods

filter_dependency(pod, specifications) click to toggle source
# File lib/cocoapods-protected-dependencies/config.rb, line 29
def filter_dependency(pod, specifications)
    return specifications unless @config_loaded

    filtered = specifications.select { |spec| spec_is_valid(pod, spec) }

    Pod::UI.puts "Dependency #{pod} is not allowed".red if filtered.empty?

    return filtered
end
load_configuration() click to toggle source
# File lib/cocoapods-protected-dependencies/config.rb, line 18
def load_configuration
    unless File.file?('protected-specs.yml')
        Pod::UI.puts "No 'protected-specs.yml' file, make sure you have created one".red
        @config_loaded = false
        return
    end

    @config = YAML.load(File.read('protected-specs.yml'))
    @config_loaded = true
end
spec_is_valid(pod, spec) click to toggle source
# File lib/cocoapods-protected-dependencies/config.rb, line 39
def spec_is_valid(pod, spec)
    # Allow external dependencies (using :git or :path), which create a local podspec
    return true if !spec.defined_in_file.nil? && spec.defined_in_file.to_s.include?('/Pods/Local Podspecs')

    config.each { |repo|
        next unless repo['source'] == spec.spec_source.url
        
        return true if !repo['lib'].nil? && repo['lib'].include?(pod)
        return true if !repo['regex'].nil? && pod.match(Regexp.new repo['regex'])
    }
    return false
end