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 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.
-
#libraries ⇒ Array<String>
A list of libraries that the user’s target needs to link against.
-
#prefix_header_contents ⇒ String
The contents of the prefix header.
-
#prefix_header_file ⇒ String
The path of the prefix header file.
-
#requires_arc ⇒ Bool
(also: #requires_arc?)
Whether the source files of the specification require to be compiled with ARC.
-
#weak_frameworks ⇒ Array<String>
A list of frameworks that the user’s target needs to weakly link against.
-
#xcconfig ⇒ Hash{String => String}
The xcconfig flags for the current 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_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.
-
#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.
-
#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.
-
#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_prefix_header_contents(value) ⇒ String
Converts the prefix header to a string if specified as an array.
-
#_prepare_resource_bundles(value) ⇒ Hash
Ensures that the file patterns of the resource bundles are contained in an array.
-
#prepare_hook_name(attr) ⇒ String
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.
33 34 35 36 37 38 39 40 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 33 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.
27 28 29 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 27 def platform_name @platform_name end |
#spec ⇒ Specification (readonly)
Returns The specification to consume.
22 23 24 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 22 def spec @spec end |
Class Method Details
.spec_attr_accessor(name) ⇒ Object
Creates a method to access the contents of the attribute.
50 51 52 53 54 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 50 def self.spec_attr_accessor(name) define_method(name) do value_for_attribute(name) end end |
Instance Method Details
#_prepare_prefix_header_contents(value) ⇒ String
Converts the prefix header to a string if specified as an array.
316 317 318 319 320 321 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 316 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
Ensures that the file patterns of the resource bundles are contained in an array.
331 332 333 334 335 336 337 338 339 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 331 def _prepare_resource_bundles(value) result = {} if value value.each do |key, patterns| result[key] = [*patterns].compact end end result end |
#compiler_flags ⇒ Array<String>
Returns the list of compiler flags needed by the specification files.
84 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 84 spec_attr_accessor :compiler_flags |
#dependencies ⇒ Array<Dependency>
Returns the dependencies on other Pods.
160 161 162 163 164 165 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 160 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.
149 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 149 spec_attr_accessor :exclude_files |
#frameworks ⇒ Array<String>
Returns A list of frameworks that the user’s target needs to link against.
69 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 69 spec_attr_accessor :frameworks |
#header_dir ⇒ String
Returns the headers directory.
101 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 101 spec_attr_accessor :header_dir |
#header_mappings_dir ⇒ String
Returns the directory from where to preserve the headers namespacing.
106 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 106 spec_attr_accessor :header_mappings_dir |
#libraries ⇒ Array<String>
Returns A list of libraries that the user’s target needs to link against.
79 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 79 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.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 249 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| if new.is_a?(Array) || old.is_a?(Array) r = [*old] + [*new] r.compact else old + ' ' + new end end else new_value end end |
#prefix_header_contents ⇒ String
Returns The contents of the prefix header.
93 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 93 spec_attr_accessor :prefix_header_contents |
#prefix_header_file ⇒ String
Returns The path of the prefix header file.
97 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 97 spec_attr_accessor :prefix_header_file |
#prepare_hook_name(attr) ⇒ String
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.
305 306 307 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 305 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.
283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 283 def prepare_value(attr, value) if attr.container == Array value = [*value].compact end hook_name = prepare_hook_name(attr) if self.respond_to?(hook_name, true) value = send(hook_name, value) else value end end |
#preserve_paths ⇒ Array<String>
Returns The paths that should be not cleaned.
154 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 154 spec_attr_accessor :preserve_paths |
#private_header_files ⇒ Array<String>
Returns the private headers of the Pod.
122 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 122 spec_attr_accessor :private_header_files |
#public_header_files ⇒ Array<String>
Returns the public headers of the Pod.
118 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 118 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.
219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 219 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_arc ⇒ Bool Also known as: requires_arc?
Returns Whether the source files of the specification require to be compiled with ARC.
63 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 63 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.
138 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 138 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.
144 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 144 spec_attr_accessor :resources |
#source_files ⇒ Array<String>
Returns the source files of the Pod.
114 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 114 spec_attr_accessor :source_files |
#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.
180 181 182 183 184 185 186 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 180 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.
198 199 200 201 202 203 204 205 206 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 198 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.
127 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 127 spec_attr_accessor :vendored_frameworks |
#vendored_libraries ⇒ Array<String>
Returns The paths of the libraries shipped with the Pod.
132 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 132 spec_attr_accessor :vendored_libraries |
#weak_frameworks ⇒ Array<String>
Returns A list of frameworks that the user’s target needs to weakly link against.
74 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 74 spec_attr_accessor :weak_frameworks |
#xcconfig ⇒ Hash{String => String}
Returns the xcconfig flags for the current specification.
89 |
# File 'lib/cocoapods-core/specification/consumer.rb', line 89 spec_attr_accessor :xcconfig |