Class: Pod::Specification::Consumer
- Inherits:
-
Object
- Object
- Pod::Specification::Consumer
- 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
-
#platform_name ⇒ Symbol
readonly
The name of the platform for which the specification needs to be consumed.
-
#spec ⇒ Specification
readonly
The specification to consume.
Regular attributes collapse
-
#compiler_flags ⇒ Array<String>
The list of compiler flags needed by the specification files.
-
#frameworks ⇒ Array<String>
A list of frameworks that the user’s target needs to link against.
-
#header_dir ⇒ String
The headers directory.
-
#header_mappings_dir ⇒ String
The directory from where to preserve the headers namespacing.
-
#info_plist ⇒ Hash{String => String}
The Info.plist values for the current specification.
-
#libraries ⇒ Array<String>
A list of libraries that the user’s target needs to link against.
-
#module_map ⇒ String
The path of the module map file.
-
#module_name ⇒ String
The module name.
-
#name ⇒ String
The name of the specification.
-
#pod_target_xcconfig ⇒ Hash{String => String}
The xcconfig flags for the current specification for the pod target.
-
#prefix_header_contents ⇒ String
The contents of the prefix header.
-
#prefix_header_file ⇒ String
The path of the prefix header file.
-
#requires_arc ⇒ Boolean
(also: #requires_arc?)
Whether the source files of the specification require to be compiled with ARC.
-
#user_target_xcconfig ⇒ Hash{String => String}
The xcconfig flags for the current specification for the user target.
-
#weak_frameworks ⇒ Array<String>
A list of frameworks that the user’s target needs to weakly link against.
Test Support collapse
-
#app_host_name ⇒ String
Name of the app host this spec requires.
-
#requires_app_host ⇒ Boolean
(also: #requires_app_host?)
Whether this test specification requires an app host.
-
#test_type ⇒ Symbol
The test type supported by this specification.
File patterns collapse
-
#dependencies ⇒ Array<Dependency>
The dependencies on other Pods.
-
#exclude_files ⇒ Array<String>
The file patterns that the Pod should ignore.
-
#merge_hash_value(attr, old, new) ⇒ Object
private
Merges two values in a hash together based on the needs of the attribute.
-
#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.
-
#on_demand_resources ⇒ Hash{String => Array<String>}
Hash where the keys are the tags of the on demand resources and the values are their relative file patterns.
-
#prepare_value(attr, value) ⇒ Object
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.
-
#preserve_paths ⇒ Array<String>
The paths that should be not cleaned.
-
#private_header_files ⇒ Array<String>
The private headers of the Pod.
-
#project_header_files ⇒ Array<String>
The project headers of the Pod.
-
#public_header_files ⇒ Array<String>
The public headers of the Pod.
-
#raw_value_for_attribute(the_spec, attr) ⇒ String, ...
Returns the value of a given attribute taking into account multi platform values.
-
#resource_bundles ⇒ Hash{String=>String}
] hash where the keys are the names of the resource bundles and the values are their relative file patterns.
-
#resources ⇒ Array<String>
A hash where the key represents the paths of the resources to copy and the values the paths of the resources that should be copied.
-
#scheme ⇒ Hash
A hash that contains the scheme configuration.
-
#script_phases ⇒ Array<Hash{Symbol=>String}>
An array of hashes where each hash represents a script phase.
-
#source_files ⇒ Array<String>
The source files of the Pod.
-
#value_for_attribute(attr_name) ⇒ String, ...
Returns the value for the attribute with the given name for the specification.
-
#value_with_inheritance(the_spec, attr) ⇒ String, ...
Returns the value of a given attribute taking into account inheritance.
-
#vendored_frameworks ⇒ Array<String>
The paths of the framework bundles shipped with the Pod.
-
#vendored_libraries ⇒ Array<String>
The paths of the libraries shipped with the Pod.
Preparing Values collapse
-
#_prepare_on_demand_resources(value) ⇒ Hash
private
Ensures that the file patterns of the on demand resources are contained in an array.
-
#_prepare_prefix_header_contents(value) ⇒ String
private
Converts the prefix header to a string if specified as an array.
-
#_prepare_resource_bundles(value) ⇒ Hash
private
Ensures that the file patterns of the resource bundles are contained in an array.
-
#_prepare_scheme(value) ⇒ Hash
private
Converts the a scheme where keys are strings into symbols.
-
#_prepare_script_phases(value) ⇒ Array<Hash{Symbol=>String}>
private
Converts the array of hashes (script phases) where keys are strings into symbols.
-
#_prepare_test_type(value) ⇒ Symbol
private
Converts the test type value from a string to a symbol.
-
#prepare_hook_name(attr) ⇒ String
private
The name of the prepare hook for this attribute.
Class Method Summary collapse
-
.spec_attr_accessor(name) ⇒ Object
Creates a method to access the contents of the attribute.
Instance Method Summary collapse
-
#initialize(spec, platform) ⇒ Consumer
constructor
A new instance of Consumer.
Constructor Details
#initialize(spec, platform) ⇒ Consumer
Returns a new instance of 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_name ⇒ Symbol (readonly)
Returns The name of the platform for which the specification needs to be consumed.
28 29 30 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 28 def platform_name @platform_name end |
#spec ⇒ Specification (readonly)
Returns The specification to consume.
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
#_prepare_on_demand_resources(value) ⇒ Hash (private)
Ensures that the file patterns of the on demand resources are contained in an array.
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 476 def _prepare_on_demand_resources(value) result = {} if value value.each do |key, patterns| case patterns when String, Array result[key] = { :paths => [*patterns].compact, :category => :download_on_demand } when Hash patterns = Specification.convert_keys_to_symbol(patterns, :recursive => false) result[key] = { :paths => [*patterns[:paths]].compact, :category => patterns.fetch(:category, :download_on_demand).to_sym } else raise StandardError, "Unknown on demand resource value type `#{patterns}`." end end end result end |
#_prepare_prefix_header_contents(value) ⇒ String (private)
Converts the prefix header to a string if specified as an array.
414 415 416 417 418 419 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 414 def _prepare_prefix_header_contents(value) if value value = value.join("\n") if value.is_a?(Array) value.strip_heredoc.chomp end end |
#_prepare_resource_bundles(value) ⇒ Hash (private)
Ensures that the file patterns of the resource bundles are contained in an array.
502 503 504 505 506 507 508 509 510 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 502 def _prepare_resource_bundles(value) result = {} if value value.each do |key, patterns| result[key] = [*patterns].compact end end result end |
#_prepare_scheme(value) ⇒ Hash (private)
Converts the a scheme where keys are strings into symbols.
464 465 466 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 464 def _prepare_scheme(value) Specification.convert_keys_to_symbol(value, :recursive => false) if value && value.is_a?(Hash) end |
#_prepare_script_phases(value) ⇒ Array<Hash{Symbol=>String}> (private)
Converts the array of hashes (script phases) where keys are strings into symbols.
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 441 def _prepare_script_phases(value) if value value.map do |script_phase| if script_phase.is_a?(Hash) phase = Specification.convert_keys_to_symbol(script_phase) phase[:execution_position] = if phase.key?(:execution_position) phase[:execution_position].to_sym else :any end phase end end.compact end end |
#_prepare_test_type(value) ⇒ Symbol (private)
Converts the test type value from a string to a symbol.
428 429 430 431 432 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 428 def _prepare_test_type(value) if value value.to_sym end end |
#app_host_name ⇒ String
Returns Name of the app host this spec requires.
153 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 153 spec_attr_accessor :app_host_name |
#compiler_flags ⇒ Array<String>
Returns the list of compiler flags needed by the specification files.
95 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 95 spec_attr_accessor :compiler_flags |
#dependencies ⇒ Array<Dependency>
Returns the dependencies on other Pods.
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_files ⇒ Array<String>
Returns The file patterns that the Pod should ignore.
219 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 219 spec_attr_accessor :exclude_files |
#frameworks ⇒ Array<String>
Returns A list of frameworks that the user’s target needs to link against.
80 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 80 spec_attr_accessor :frameworks |
#header_dir ⇒ String
Returns the headers directory.
135 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 135 spec_attr_accessor :header_dir |
#header_mappings_dir ⇒ String
Returns the directory from where to preserve the headers namespacing.
140 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 140 spec_attr_accessor :header_mappings_dir |
#info_plist ⇒ Hash{String => String}
Returns the Info.plist values for the current specification.
115 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 115 spec_attr_accessor :info_plist |
#libraries ⇒ Array<String>
Returns A list of libraries that the user’s target needs to link against.
90 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 90 spec_attr_accessor :libraries |
#merge_hash_value(attr, old, new) ⇒ Object (private)
Merges two values in a hash together based on the needs of the attribute
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 378 def merge_hash_value(attr, old, new) case attr.name when :info_plist new when ->(name) { spec.non_library_specification? && [:pod_target_xcconfig, :user_target_xcconfig, :xcconfig].include?(name) } new else if new.is_a?(Array) || old.is_a?(Array) r = Array(old) + Array(new) r.compact else old + ' ' + new end end end |
#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_map ⇒ String
Returns the path of the module map file.
131 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 131 spec_attr_accessor :module_map |
#module_name ⇒ String
Returns the module name.
127 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 127 spec_attr_accessor :module_name |
#name ⇒ String
Returns The name of the specification.
69 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 69 spec_attr_accessor :name |
#on_demand_resources ⇒ Hash{String => Array<String>}
Returns hash where the keys are the tags of the on demand resources and the values are their relative file patterns.
193 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 193 spec_attr_accessor :on_demand_resources |
#pod_target_xcconfig ⇒ Hash{String => String}
Returns the xcconfig flags for the current specification for the pod target.
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_contents ⇒ String
Returns The contents of the prefix header.
119 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 119 spec_attr_accessor :prefix_header_contents |
#prefix_header_file ⇒ String
Returns The path of the prefix header file.
123 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 123 spec_attr_accessor :prefix_header_file |
#prepare_hook_name(attr) ⇒ String (private)
The hook is called after the value has been wrapped in an array (if needed according to the container) but before validation.
Returns the name of the prepare hook for this attribute.
403 404 405 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 403 def prepare_hook_name(attr) "_prepare_#{attr.name}" end |
#prepare_value(attr, value) ⇒ Object
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_paths ⇒ Array<String>
Returns The paths that should be not cleaned.
224 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 224 spec_attr_accessor :preserve_paths |
#private_header_files ⇒ Array<String>
Returns the private headers of the Pod.
177 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 177 spec_attr_accessor :private_header_files |
#project_header_files ⇒ Array<String>
Returns the project headers of the Pod.
173 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 173 spec_attr_accessor :project_header_files |
#public_header_files ⇒ Array<String>
Returns the public headers of the Pod.
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_host ⇒ Boolean Also known as: requires_app_host?
Returns Whether this test specification requires an app host.
148 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 148 spec_attr_accessor :requires_app_host |
#requires_arc ⇒ Boolean Also known as: requires_arc?
Returns Whether the source files of the specification require to be compiled with ARC.
74 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 74 spec_attr_accessor :requires_arc |
#resource_bundles ⇒ Hash{String=>String}
Returns ] hash where the keys are the names of the resource bundles and the values are their relative file patterns.
199 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 199 spec_attr_accessor :resource_bundles |
#resources ⇒ Array<String>
Returns A hash where the key represents the paths of the resources to copy and the values the paths of the resources that should be copied.
214 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 214 spec_attr_accessor :resources |
#scheme ⇒ Hash
Returns A hash that contains the scheme configuration.
208 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 208 spec_attr_accessor :scheme |
#script_phases ⇒ Array<Hash{Symbol=>String}>
Returns An array of hashes where each hash represents a script phase.
204 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 204 spec_attr_accessor :script_phases |
#source_files ⇒ Array<String>
Returns the source files of the Pod.
165 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 165 spec_attr_accessor :source_files |
#test_type ⇒ Symbol
Returns the test type supported by this specification.
157 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 157 spec_attr_accessor :test_type |
#user_target_xcconfig ⇒ Hash{String => String}
Returns the xcconfig flags for the current specification for the user target.
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_frameworks ⇒ Array<String>
Returns The paths of the framework bundles shipped with the Pod.
182 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 182 spec_attr_accessor :vendored_frameworks |
#vendored_libraries ⇒ Array<String>
Returns The paths of the libraries shipped with the Pod.
187 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 187 spec_attr_accessor :vendored_libraries |
#weak_frameworks ⇒ Array<String>
Returns A list of frameworks that the user’s target needs to weakly link against.
85 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 85 spec_attr_accessor :weak_frameworks |