Class: Pod::SPM::Package

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-spm/def/spm_package.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Package

Returns a new instance of Package.



9
10
11
12
13
14
15
16
17
18
# File 'lib/cocoapods-spm/def/spm_package.rb', line 9

def initialize(name, options = {})
  @name = name
  @_options = options
  @relative_path = nil
  @linkage = nil
  @url = nil
  @requirement = nil
  @linking_opts = {}
  parse_options(options)
end

Instance Attribute Details

#linking_optsObject (readonly)

Returns the value of attribute linking_opts.



7
8
9
# File 'lib/cocoapods-spm/def/spm_package.rb', line 7

def linking_opts
  @linking_opts
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/cocoapods-spm/def/spm_package.rb', line 7

def name
  @name
end

#relative_pathObject (readonly)

Returns the value of attribute relative_path.



7
8
9
# File 'lib/cocoapods-spm/def/spm_package.rb', line 7

def relative_path
  @relative_path
end

#requirementObject (readonly)

Returns the value of attribute requirement.



7
8
9
# File 'lib/cocoapods-spm/def/spm_package.rb', line 7

def requirement
  @requirement
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/cocoapods-spm/def/spm_package.rb', line 7

def url
  @url
end

Instance Method Details

#absolute_pathObject



32
33
34
# File 'lib/cocoapods-spm/def/spm_package.rb', line 32

def absolute_path
  (Pathname("Pods") / relative_path).realpath.to_s
end

#create_pkg_ref(project) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/cocoapods-spm/def/spm_package.rb', line 75

def create_pkg_ref(project)
  cls = local? ? Object::XCLocalSwiftPackageReference : Object::XCRemoteSwiftPackageReference
  ref = project.new(cls)
  ref.name = name
  if local?
    ref.relative_path = relative_path
  else
    ref.repositoryURL = url
    ref.requirement = requirement
  end
  ref
end

#inspectObject Also known as: to_s



45
46
47
# File 'lib/cocoapods-spm/def/spm_package.rb', line 45

def inspect
  "#<#{self.class} #{name}>"
end

#linker_flagsObject



63
64
65
# File 'lib/cocoapods-spm/def/spm_package.rb', line 63

def linker_flags
  @linking_opts[:linker_flags] || []
end

#local?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/cocoapods-spm/def/spm_package.rb', line 51

def local?
  @relative_path != nil
end

#parse_options(options) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/cocoapods-spm/def/spm_package.rb', line 20

def parse_options(options)
  @url = options[:url] || options[:git]
  @relative_path = relative_path_from(options)
  @requirement = requirement_from(options)
  @linking_opts = options[:linking] || {}
  validate!
end

#relative_path_from(options) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/cocoapods-spm/def/spm_package.rb', line 36

def relative_path_from(options)
  if (relative_path = options[:relative_path])
    relative_path
  elsif (path = options[:path])
    path = Pathname(path).expand_path
    path.relative_path_from(File.absolute_path("Pods")).to_s
  end
end

#should_exclude_from_target?(target_name) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/cocoapods-spm/def/spm_package.rb', line 59

def should_exclude_from_target?(target_name)
  @linking_opts.fetch(:exclude_from_targets, []).include?(target_name.delete_prefix('Pods-'))
end

#slugObject



28
29
30
# File 'lib/cocoapods-spm/def/spm_package.rb', line 28

def slug
  @slug ||= File.basename(@url || @relative_path, ".*")
end

#to_dependenciesObject



67
68
69
70
71
72
73
# File 'lib/cocoapods-spm/def/spm_package.rb', line 67

def to_dependencies
  if (products = @_options[:products])
    products.map { |product| Dependency.new(@name, product: product, pkg: self) }
  else
    [Dependency.new(@name, pkg: self)]
  end
end

#use_default_xcode_linking?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/cocoapods-spm/def/spm_package.rb', line 55

def use_default_xcode_linking?
  @linking_opts.fetch(:use_default_xcode_linking, false)
end