class Pod::Installer::InstallationOptions

Represents the installation options the user can customize via a ‘Podfile`.

Public Class Methods

all_options() click to toggle source

@return [Array<Symbol>] the names of all known installation options.

# File lib/cocoapods/installer/installation_options.rb, line 60
def self.all_options
  defaults.keys
end
defaults() click to toggle source

@return [Hash<Symbol,Object>] all known installation options and their

default values.
# File lib/cocoapods/installer/installation_options.rb, line 54
def self.defaults
  @defaults ||= {}
end
from_podfile(podfile) click to toggle source

Parses installation options from a podfile.

@param [Podfile] podfile the podfile to parse installation options

from.

@raise [Informative] if ‘podfile` does not specify a `CocoaPods`

install.

@return [Self]

# File lib/cocoapods/installer/installation_options.rb, line 19
def self.from_podfile(podfile)
  name, options = podfile.installation_method
  unless name.downcase == 'cocoapods'
    raise Informative, "Currently need to specify a `cocoapods` install, you chose `#{name}`."
  end
  new(options)
end
new(options = {}) click to toggle source

Initializes the installation options with a hash of options from a Podfile.

@param [Hash] options the options to parse.

@raise [Informative] if ‘options` contains any unknown keys.

# File lib/cocoapods/installer/installation_options.rb, line 71
def initialize(options = {})
  options = ActiveSupport::HashWithIndifferentAccess.new(options)
  unknown_keys = options.keys - self.class.all_options.map(&:to_s)
  raise Informative, "Unknown installation options: #{unknown_keys.to_sentence}." unless unknown_keys.empty?
  self.class.defaults.each do |key, default|
    value = options.fetch(key, default)
    send("#{key}=", value)
  end
end
option(name, default, boolean: true) click to toggle source

Defines a new installation option.

@param [#to_s] name the name of the option.

@param default the default value for the option.

@param [Boolean] boolean whether the option has a boolean value.

@return [void]

@!macro [attach] option

@note this option defaults to $2.

@return [Boolean] the $1 $0 for installation.
# File lib/cocoapods/installer/installation_options.rb, line 43
def self.option(name, default, boolean: true)
  name = name.to_s
  raise ArgumentError, "The `#{name}` option is already defined" if defaults.key?(name)
  defaults[name] = default
  attr_accessor name
  alias_method "#{name}?", name if boolean
end

Public Instance Methods

==(other) click to toggle source
# File lib/cocoapods/installer/installation_options.rb, line 94
def ==(other)
  other.is_a?(self.class) && to_h == other.to_h
end
Also aliased as: eql
eql(other)
Alias for: ==
hash() click to toggle source
# File lib/cocoapods/installer/installation_options.rb, line 100
def hash
  to_h.hash
end
to_h(include_defaults: true) click to toggle source

@param [Boolean] include_defaults whether values that match the default

for their option should be included. Defaults to `true`.

@return [Hash] the options, keyed by option name.

# File lib/cocoapods/installer/installation_options.rb, line 86
def to_h(include_defaults: true)
  self.class.defaults.reduce(ActiveSupport::HashWithIndifferentAccess.new) do |hash, (option, default)|
    value = send(option)
    hash[option] = value if include_defaults || value != default
    hash
  end
end