Class: SourceValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-whitelist/validator/source_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(private_specs, private_sources) ⇒ SourceValidator

Returns a new instance of SourceValidator.



6
7
8
9
# File 'lib/cocoapods-whitelist/validator/source_validator.rb', line 6

def initialize(private_specs, private_sources)
    @private_specs = private_specs
    @private_sources = private_sources
end

Instance Attribute Details

#private_sourcesObject

Returns the value of attribute private_sources.



5
6
7
# File 'lib/cocoapods-whitelist/validator/source_validator.rb', line 5

def private_sources
  @private_sources
end

#private_specsObject

Returns the value of attribute private_specs.



4
5
6
# File 'lib/cocoapods-whitelist/validator/source_validator.rb', line 4

def private_specs
  @private_specs
end

Instance Method Details

#filter_dependency(pod, specifications) ⇒ Object

Filters the valids specifications for a given pod Params:

pod

podname to be validated

specifications

potencial unsecure specs



16
17
18
# File 'lib/cocoapods-whitelist/validator/source_validator.rb', line 16

def filter_dependency(pod, specifications)
    return specifications.select { |spec| spec_is_valid(pod, spec) }  
end

#spec_is_valid(pod, spec) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cocoapods-whitelist/validator/source_validator.rb', line 20

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')
    
    # Allow every dependency that comes from our privates sources
    return true if @private_sources.include? spec.spec_source.url

    # NO dependency that comes from a public source should be in our private specs
    return true if !@private_specs.include? spec.name

    return false
end