Class: Pod::Specification::DSL::Attribute

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

Overview

A Specification attribute stores the information of an attribute. It also provides logic to implement any required logic.

Constant Summary collapse

SUPPORTED_SPEC_TYPES =

Spec types currently supported.

[:library, :app, :test].freeze

Options collapse

Instance Attribute Summary collapse

Options collapse

Accessors support collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options) ⇒ Attribute

Returns a new attribute initialized with the given options.

Attributes by default are:

  • inherited

  • multi-platform

Raises:

  • If there are unrecognized options.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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

Instance Attribute Details

#containerClass (readonly)



92
93
94
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 92

def container
  @container
end

#default_valueObject (readonly)

Note:

The default value is not automatically wrapped and should be specified within the container if any.

Returns if the attribute follows configuration over convention it can specify a default value.



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

def default_value
  @default_value
end

#ios_defaultObject (readonly)



112
113
114
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 112

def ios_default
  @ios_default
end

#keysArray, Hash (readonly)

Note:

A hash is accepted to group the keys associated only with certain keys (see the source attribute of a Spec).

Returns the list of the accepted keys for an attribute wrapped by a Hash.



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

def keys
  @keys
end

#nameSymbol (readonly)



16
17
18
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 16

def name
  @name
end

#osx_defaultObject (readonly)



116
117
118
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 116

def osx_default
  @osx_default
end

#typesArray<Class> (readonly)



79
80
81
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 79

def types
  @types
end

Instance Method Details

#default(platform = nil) ⇒ Object

Returns the default value for the attribute.



181
182
183
184
185
186
187
188
189
# 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

#file_patterns?Boolean

Note:

This is mostly used by the linter.

Returns whether the attribute describes file patterns.



157
158
159
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 157

def file_patterns?
  @file_patterns
end

#inherited?Boolean

Note:

Attributes stored in wrappers are always inherited.

values with the parent.



166
167
168
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 166

def inherited?
  @inherited
end

#inspectString



66
67
68
69
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 66

def inspect
  "<#{self.class} name=#{name} types=#{types} " \
    "multi_platform=#{multi_platform?}>"
end

#multi_platform?Boolean



142
143
144
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 142

def multi_platform?
  @multi_platform
end

#required?Boolean



121
122
123
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 121

def required?
  @required
end

#root_only?Boolean



128
129
130
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 128

def root_only?
  @root_only
end

#singularize?Boolean



149
150
151
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 149

def singularize?
  @singularize
end

#supported_typesArray<Class>



84
85
86
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 84

def supported_types
  @supported_types ||= @types.dup.push(container).compact
end

#test_only?Boolean



135
136
137
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 135

def test_only?
  @spec_types == [:test]
end

#to_sString



60
61
62
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 60

def to_s
  "Specification attribute `#{name}`"
end

#writer_nameString



193
194
195
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 193

def writer_name
  "#{name}="
end

#writer_singular_formString



200
201
202
# File 'lib/cocoapods-core/specification/dsl/attribute.rb', line 200

def writer_singular_form
  "#{name.to_s.singularize}=" if singularize?
end