Class: Pod::Specification::DSL::PlatformProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-core/specification/dsl/platform_proxy.rb

Overview

The PlatformProxy works in conjunction with Specification#_on_platform. It provides support for a syntax like ‘spec.ios.source_files = ’file’‘.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec, platform) ⇒ PlatformProxy

Returns a new instance of PlatformProxy.

Parameters:

  • spec (Specification)

    @see spec

  • platform (Symbol)

    @see platform



22
23
24
# File 'lib/cocoapods-core/specification/dsl/platform_proxy.rb', line 22

def initialize(spec, platform)
  @spec, @platform = spec, platform
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ void

This method returns an undefined value.

Defines a setter method for each attribute of the specification class, that forwards the message to the #specification using the Specification#on_platform method.



32
33
34
35
36
37
38
39
40
41
# File 'lib/cocoapods-core/specification/dsl/platform_proxy.rb', line 32

def method_missing(meth, *args, &block)
  attr = Specification::DSL.attributes.values.find do |attr|
    attr.writer_name.to_sym == meth || (attr.writer_singular_form && attr.writer_singular_form.to_sym == meth)
  end
  if attr && attr.multi_platform?
    spec.store_attribute(attr.name, args.first, platform)
  else
    super
  end
end

Instance Attribute Details

#platformSymbol

Returns the platform described by this proxy. Can be either ‘:ios` or `:osx`.

Returns:

  • (Symbol)

    the platform described by this proxy. Can be either ‘:ios` or `:osx`.



17
18
19
# File 'lib/cocoapods-core/specification/dsl/platform_proxy.rb', line 17

def platform
  @platform
end

#specSpecification

Returns the specification for this platform proxy.

Returns:



12
13
14
# File 'lib/cocoapods-core/specification/dsl/platform_proxy.rb', line 12

def spec
  @spec
end

Instance Method Details

#dependency(*args) ⇒ void

This method returns an undefined value.

Allows to add dependency for the platform.



47
48
49
50
51
52
53
# File 'lib/cocoapods-core/specification/dsl/platform_proxy.rb', line 47

def dependency(*args)
  name, *version_requirements = args
  platform_name = platform.to_s
  spec.attributes_hash[platform_name] ||= {}
  spec.attributes_hash[platform_name]["dependencies"] ||= {}
  spec.attributes_hash[platform_name]["dependencies"][name] = version_requirements
end

#deployment_target=(value) ⇒ void

This method returns an undefined value.

Allows to set the deployment target for the platform.



59
60
61
62
63
# File 'lib/cocoapods-core/specification/dsl/platform_proxy.rb', line 59

def deployment_target=(value)
  platform_name = platform.to_s
  spec.attributes_hash["platforms"] ||= {}
  spec.attributes_hash["platforms"][platform_name] = value
end