Class: Pod::Specification::Consumer

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

Overview

Allows to conveniently access a Specification programmatically.

It takes care of:

  • standardizing the attributes

  • handling multi-platform values

  • handle default values

  • handle automatic container wrapping of values

  • handle inherited values

This class allows to store the values of the attributes in the Specification as specified in the DSL. The benefits is reduced reliance on meta programming to access the attributes and the possibility of serializing a specification back exactly as defined in a file.

Instance Attribute Summary collapse

Regular attributes collapse

Test Support collapse

File patterns collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec, platform) ⇒ Consumer



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

def initialize(spec, platform)
  @spec = spec
  @platform_name = platform.is_a?(Symbol) ? platform : platform.name

  unless spec.supported_on_platform?(platform)
    raise StandardError, "#{self} is not compatible with #{platform}."
  end
end

Instance Attribute Details

#platform_nameSymbol (readonly)



28
29
30
# File 'lib/cocoapods-core/specification/consumer.rb', line 28

def platform_name
  @platform_name
end

#specSpecification (readonly)



23
24
25
# File 'lib/cocoapods-core/specification/consumer.rb', line 23

def spec
  @spec
end

Class Method Details

.spec_attr_accessor(name) ⇒ Object

Creates a method to access the contents of the attribute.



51
52
53
54
55
# File 'lib/cocoapods-core/specification/consumer.rb', line 51

def self.spec_attr_accessor(name)
  define_method(name) do
    value_for_attribute(name)
  end
end

Instance Method Details

#app_host_nameString



153
# File 'lib/cocoapods-core/specification/consumer.rb', line 153

spec_attr_accessor :app_host_name

#compiler_flagsArray<String>



95
# File 'lib/cocoapods-core/specification/consumer.rb', line 95

spec_attr_accessor :compiler_flags

#dependenciesArray<Dependency>



230
231
232
233
234
235
# File 'lib/cocoapods-core/specification/consumer.rb', line 230

def dependencies
  value = value_for_attribute(:dependencies)
  value.map do |name, requirements|
    Dependency.new(name, requirements)
  end
end

#exclude_filesArray<String>



219
# File 'lib/cocoapods-core/specification/consumer.rb', line 219

spec_attr_accessor :exclude_files

#frameworksArray<String>



80
# File 'lib/cocoapods-core/specification/consumer.rb', line 80

spec_attr_accessor :frameworks

#header_dirString



135
# File 'lib/cocoapods-core/specification/consumer.rb', line 135

spec_attr_accessor :header_dir

#header_mappings_dirString



140
# File 'lib/cocoapods-core/specification/consumer.rb', line 140

spec_attr_accessor :header_mappings_dir

#info_plistHash{String => String}



115
# File 'lib/cocoapods-core/specification/consumer.rb', line 115

spec_attr_accessor :info_plist

#librariesArray<String>



90
# File 'lib/cocoapods-core/specification/consumer.rb', line 90

spec_attr_accessor :libraries

#merge_values(attr, existing_value, new_value) ⇒ String, ...

Merges the values of an attribute, either because the attribute is multi platform or because it is inherited.



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/cocoapods-core/specification/consumer.rb', line 319

def merge_values(attr, existing_value, new_value)
  return existing_value if new_value.nil?
  return new_value if existing_value.nil?

  if attr.types.include?(TrueClass)
    new_value.nil? ? existing_value : new_value
  elsif attr.container == Array
    r = [*existing_value] + [*new_value]
    r.compact
  elsif attr.container == Hash
    existing_value.merge(new_value) do |_, old, new|
      merge_hash_value(attr, old, new)
    end
  else
    new_value
  end
end

#module_mapString



131
# File 'lib/cocoapods-core/specification/consumer.rb', line 131

spec_attr_accessor :module_map

#module_nameString



127
# File 'lib/cocoapods-core/specification/consumer.rb', line 127

spec_attr_accessor :module_name

#nameString



69
# File 'lib/cocoapods-core/specification/consumer.rb', line 69

spec_attr_accessor :name

#on_demand_resourcesHash{String => Array<String>}



193
# File 'lib/cocoapods-core/specification/consumer.rb', line 193

spec_attr_accessor :on_demand_resources

#pod_target_xcconfigHash{String => String}



100
101
102
103
# File 'lib/cocoapods-core/specification/consumer.rb', line 100

def pod_target_xcconfig
  attr = Specification::DSL.attributes[:pod_target_xcconfig]
  merge_values(attr, value_for_attribute(:xcconfig), value_for_attribute(:pod_target_xcconfig))
end

#prefix_header_contentsString



119
# File 'lib/cocoapods-core/specification/consumer.rb', line 119

spec_attr_accessor :prefix_header_contents

#prefix_header_fileString



123
# File 'lib/cocoapods-core/specification/consumer.rb', line 123

spec_attr_accessor :prefix_header_file

#prepare_value(attr, value) ⇒ Object

Note:

Only array containers are wrapped. To automatically wrap values for attributes with hash containers a prepare hook should be used.

Wraps a value in an Array if needed and calls the prepare hook to allow further customization of a value before storing it in the instance variable.



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/cocoapods-core/specification/consumer.rb', line 348

def prepare_value(attr, value)
  if attr.container == Array
    value = if value.is_a?(Hash)
              [value]
            else
              [*value].compact
            end
  end

  hook_name = prepare_hook_name(attr)
  if self.respond_to?(hook_name, true)
    send(hook_name, value)
  else
    value
  end
end

#preserve_pathsArray<String>



224
# File 'lib/cocoapods-core/specification/consumer.rb', line 224

spec_attr_accessor :preserve_paths

#private_header_filesArray<String>



177
# File 'lib/cocoapods-core/specification/consumer.rb', line 177

spec_attr_accessor :private_header_files

#project_header_filesArray<String>



173
# File 'lib/cocoapods-core/specification/consumer.rb', line 173

spec_attr_accessor :project_header_files

#public_header_filesArray<String>



169
# File 'lib/cocoapods-core/specification/consumer.rb', line 169

spec_attr_accessor :public_header_files

#raw_value_for_attribute(the_spec, attr) ⇒ String, ...

Returns the value of a given attribute taking into account multi platform values.



289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/cocoapods-core/specification/consumer.rb', line 289

def raw_value_for_attribute(the_spec, attr)
  value = the_spec.attributes_hash[attr.name.to_s]
  value = prepare_value(attr, value)

  if attr.multi_platform?
    if platform_hash = the_spec.attributes_hash[platform_name.to_s]
      platform_value = platform_hash[attr.name.to_s]
      platform_value = prepare_value(attr, platform_value)
      value = merge_values(attr, value, platform_value)
    end
  end
  value
end

#requires_app_hostBoolean Also known as: requires_app_host?



148
# File 'lib/cocoapods-core/specification/consumer.rb', line 148

spec_attr_accessor :requires_app_host

#requires_arcBoolean Also known as: requires_arc?



74
# File 'lib/cocoapods-core/specification/consumer.rb', line 74

spec_attr_accessor :requires_arc

#resource_bundlesHash{String=>String}



199
# File 'lib/cocoapods-core/specification/consumer.rb', line 199

spec_attr_accessor :resource_bundles

#resourcesArray<String>



214
# File 'lib/cocoapods-core/specification/consumer.rb', line 214

spec_attr_accessor :resources

#schemeHash



208
# File 'lib/cocoapods-core/specification/consumer.rb', line 208

spec_attr_accessor :scheme

#script_phasesArray<Hash{Symbol=>String}>



204
# File 'lib/cocoapods-core/specification/consumer.rb', line 204

spec_attr_accessor :script_phases

#source_filesArray<String>



165
# File 'lib/cocoapods-core/specification/consumer.rb', line 165

spec_attr_accessor :source_files

#test_typeSymbol



157
# File 'lib/cocoapods-core/specification/consumer.rb', line 157

spec_attr_accessor :test_type

#user_target_xcconfigHash{String => String}



108
109
110
111
# File 'lib/cocoapods-core/specification/consumer.rb', line 108

def user_target_xcconfig
  attr = Specification::DSL.attributes[:user_target_xcconfig]
  merge_values(attr, value_for_attribute(:xcconfig), value_for_attribute(:user_target_xcconfig))
end

#value_for_attribute(attr_name) ⇒ String, ...

Returns the value for the attribute with the given name for the specification. It takes into account inheritance, multi-platform attributes and default values.



250
251
252
253
254
255
256
# File 'lib/cocoapods-core/specification/consumer.rb', line 250

def value_for_attribute(attr_name)
  attr = Specification::DSL.attributes[attr_name]
  value = value_with_inheritance(spec, attr)
  value = attr.default(platform_name) if value.nil?
  value = attr.container.new if value.nil? && attr.container
  value
end

#value_with_inheritance(the_spec, attr) ⇒ String, ...

Returns the value of a given attribute taking into account inheritance.



268
269
270
271
272
273
274
275
276
# File 'lib/cocoapods-core/specification/consumer.rb', line 268

def value_with_inheritance(the_spec, attr)
  value = raw_value_for_attribute(the_spec, attr)
  if the_spec.root? || !attr.inherited?
    return value
  end

  parent_value = value_with_inheritance(the_spec.parent, attr)
  merge_values(attr, parent_value, value)
end

#vendored_frameworksArray<String>



182
# File 'lib/cocoapods-core/specification/consumer.rb', line 182

spec_attr_accessor :vendored_frameworks

#vendored_librariesArray<String>



187
# File 'lib/cocoapods-core/specification/consumer.rb', line 187

spec_attr_accessor :vendored_libraries

#weak_frameworksArray<String>



85
# File 'lib/cocoapods-core/specification/consumer.rb', line 85

spec_attr_accessor :weak_frameworks