class Pod::Specification::DSL::Attribute
A Specification
attribute stores the information of an attribute. It also provides logic to implement any required logic.
Constants
- SUPPORTED_SPEC_TYPES
Spec
types currently supported.
Attributes
@return [Class] if defined it can be #{Array} or #{Hash}. It is used
as default initialization value and to automatically wrap other values to arrays.
@return [Object] if the attribute follows configuration over
convention it can specify a default value.
@note The default value is not automatically wrapped and should be
specified within the container if any.
@return [Object] similar to #{default_value} but for iOS.
@return [Array, Hash] the list of the accepted keys for an attribute
wrapped by a Hash.
@note A hash is accepted to group the keys associated only with
certain keys (see the source attribute of a Spec).
@return [Symbol] the name of the attribute.
@return [Object] similar to #{default_value} but for OS X.
@return [Array<Class>] the list of the classes of the values
supported by the attribute writer. If not specified defaults to #{String}.
Public Class Methods
Returns a new attribute initialized with the given options.
Attributes by default are:
-
inherited
-
multi-platform
@param [Symbol] name @see name
@param [Hash{Symbol=>Object}] options
The options for configuring the attribute (see Options group).
@raise If there are unrecognized options.
# File lib/cocoapods-core/specification/dsl/attribute.rb, line 33 def initialize(name, options) @name = name @multi_platform = options.delete(:multi_platform) { true } @root_only = options.delete(:root_only) { false } @spec_types = options.delete(:spec_types) { SUPPORTED_SPEC_TYPES } @inherited = options.delete(:inherited) { @root_only } @required = options.delete(:required) { false } @singularize = options.delete(:singularize) { false } @file_patterns = options.delete(:file_patterns) { false } @container = options.delete(:container) { nil } @keys = options.delete(:keys) { nil } @default_value = options.delete(:default_value) { nil } @ios_default = options.delete(:ios_default) { nil } @osx_default = options.delete(:osx_default) { nil } @types = options.delete(:types) { [String] } unless options.empty? raise StandardError, "Unrecognized options: #{options} for #{self}" end unless (@spec_types - SUPPORTED_SPEC_TYPES).empty? raise StandardError, "Unrecognized spec type option: #{@spec_types} for #{self}" end end
Public Instance Methods
Returns the default value for the attribute.
@param [Symbol] platform
the platform for which the default value is requested.
@return [Object] The default value.
# File lib/cocoapods-core/specification/dsl/attribute.rb, line 181 def default(platform = nil) if platform && multi_platform? platform_value = ios_default if platform == :ios platform_value = osx_default if platform == :osx platform_value || default_value else default_value end end
@return [Boolean] whether the attribute describes file patterns.
@note This is mostly used by the linter.
# File lib/cocoapods-core/specification/dsl/attribute.rb, line 157 def file_patterns? @file_patterns end
@return [Boolean] defines whether the attribute reader should join the values with the parent.
@note Attributes stored in wrappers are always inherited.
# File lib/cocoapods-core/specification/dsl/attribute.rb, line 166 def inherited? @inherited end
@return [String] A string representation suitable for debugging.
# File lib/cocoapods-core/specification/dsl/attribute.rb, line 66 def inspect "<#{self.class} name=#{name} types=#{types} " \ "multi_platform=#{multi_platform?}>" end
@return [Boolean] whether the attribute is multi-platform and should
work in conjunction with #{PlatformProxy}.
# File lib/cocoapods-core/specification/dsl/attribute.rb, line 142 def multi_platform? @multi_platform end
@return [Boolean] whether the specification should be considered invalid
if a value for the attribute is not specified.
# File lib/cocoapods-core/specification/dsl/attribute.rb, line 121 def required? @required end
@return [Boolean] whether the attribute should be specified only on the
root specification.
# File lib/cocoapods-core/specification/dsl/attribute.rb, line 128 def root_only? @root_only end
@return [Boolean] whether there should be a singular alias for the
attribute writer.
# File lib/cocoapods-core/specification/dsl/attribute.rb, line 149 def singularize? @singularize end
@return [Array<Class>] the list of the classes of the values
supported by the attribute, including the container.
# File lib/cocoapods-core/specification/dsl/attribute.rb, line 84 def supported_types @supported_types ||= @types.dup.push(container).compact end
@return [Boolean] whether the attribute should be specified only on
test specifications.
# File lib/cocoapods-core/specification/dsl/attribute.rb, line 135 def test_only? @spec_types == [:test] end
@return [String] A string representation suitable for UI.
# File lib/cocoapods-core/specification/dsl/attribute.rb, line 60 def to_s "Specification attribute `#{name}`" end
@return [String] the name of the setter method for the attribute.
# File lib/cocoapods-core/specification/dsl/attribute.rb, line 193 def writer_name "#{name}=" end
@return [String] an aliased attribute writer offered for convenience
on the DSL.
# File lib/cocoapods-core/specification/dsl/attribute.rb, line 200 def writer_singular_form "#{name.to_s.singularize}=" if singularize? end