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



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

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

#create_pkg_ref(project) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/cocoapods-spm/def/spm_package.rb', line 70

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



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

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

#linker_flagsObject



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

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

#local?Boolean

Returns:

  • (Boolean)


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

def local?
  @relative_path != nil
end

#parse_options(options) ⇒ Object



20
21
22
23
24
25
# 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] || {}
end

#relative_path_from(options) ⇒ Object



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

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

#slugObject



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

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

#to_dependenciesObject



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

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)


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

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