Class: Pod::Generate::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/generate/configuration.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.optionsArray<Option> (readonly)

Returns all of the options available in the configuration.

Returns:

  • (Array<Option>)

    all of the options available in the configuration



11
12
13
# File 'lib/cocoapods/generate/configuration.rb', line 11

def options
  @options
end

Instance Attribute Details

#app_host_source_dir[String, Pathname] (readonly)

defaults to ‘nil`

Returns:

  • ([String, Pathname])

    A directory containing sources to use for the app host



156
157
158
159
160
# File 'lib/cocoapods/generate/configuration.rb', line 156

option :app_host_source_dir, [String, Pathname], 'nil',
'A directory containing sources to use for the app host',
'DIR',
->(dir) { 'not a directory' unless dir.directory? },
coerce_to_pathname

#auto_openBOOLEAN (readonly)

defaults to ‘false`

Returns:

  • (BOOLEAN)

    Whether to automatically open the generated workspaces



153
# File 'lib/cocoapods/generate/configuration.rb', line 153

option :auto_open, BOOLEAN, 'false', 'Whether to automatically open the generated workspaces', nil, nil, coerce_to_bool

#cleanBOOLEAN (readonly)

defaults to ‘false`

Returns:

  • (BOOLEAN)

    Whether to clean the generated directories before generating



154
# File 'lib/cocoapods/generate/configuration.rb', line 154

option :clean, BOOLEAN, 'false', 'Whether to clean the generated directories before generating', nil, nil, coerce_to_bool

#deterministic_uuidsBOOLEAN (readonly)

defaults to ‘false`

Returns:

  • (BOOLEAN)

    Whether installation should use deterministic UUIDs for pods projects



184
# File 'lib/cocoapods/generate/configuration.rb', line 184

option :deterministic_uuids, BOOLEAN, 'false', 'Whether installation should use deterministic UUIDs for pods projects', nil, nil, coerce_to_bool

#gen_directory[String, Pathname] (readonly)

defaults to ‘Pathname(“gen”).expand_path`

Returns:

  • ([String, Pathname])

    Path to generate workspaces in



152
# File 'lib/cocoapods/generate/configuration.rb', line 152

option :gen_directory, [String, Pathname], 'Pathname("gen").expand_path', 'Path to generate workspaces in', 'PATH', ->(path) { 'path is file' if path.file? }, coerce_to_pathname

#lockfile[Pod::Lockfile] (readonly)

defaults to ‘pod_config.lockfile`

Returns:

  • ([Pod::Lockfile])

    nil



146
# File 'lib/cocoapods/generate/configuration.rb', line 146

option :lockfile, [Pod::Lockfile], 'pod_config.lockfile', nil

#pod_configConfig (readonly)

defaults to ‘Pod::Config.instance`

Returns:

  • (Config)

    nil



133
# File 'lib/cocoapods/generate/configuration.rb', line 133

option :pod_config, Config, 'Pod::Config.instance', nil

#podfile[Podfile] (readonly)

defaults to ‘Podfile.from_file(podfile_path) if (podfile_path && File.file?(File.expand_path(podfile_path)))`

Returns:

  • ([Podfile])


136
# File 'lib/cocoapods/generate/configuration.rb', line 136

option :podfile, [Podfile], 'Podfile.from_file(podfile_path) if (podfile_path && File.file?(File.expand_path(podfile_path)))'

#podfile_path[String, Pathname] (readonly)

defaults to ‘pod_config.podfile_path`

Returns:

  • ([String, Pathname])

    Path to podfile to use



135
# File 'lib/cocoapods/generate/configuration.rb', line 135

option :podfile_path, [String, Pathname], 'pod_config.podfile_path', 'Path to podfile to use', 'PATH', ->(path) { 'file does not exist' unless path.file? }, coerce_to_pathname

#podfile_pluginsnew (readonly)

defaults to ‘(use_podfile && podfile) ? podfile.plugins : {}`

Returns:

  • (new)

    nil



139
140
141
142
143
144
# File 'lib/cocoapods/generate/configuration.rb', line 139

option :podfile_plugins, HashOf.new(keys: [String], values: [NilClass, HashOf.new(keys: [String], values: [TrueClass, FalseClass, NilClass, String, Hash, Array])]),
'(use_podfile && podfile) ? podfile.plugins : {}',
nil,
nil,
nil,
->(hash) { Hash[hash] }

#podspec_pathsnew (readonly)

defaults to ‘[Pathname(?.)]`

Returns:

  • (new)

    nil



162
163
164
165
166
167
# File 'lib/cocoapods/generate/configuration.rb', line 162

option :podspec_paths, ArrayOf.new(String, Pathname, URI),
'[Pathname(?.)]',
nil,
nil,
->(paths) { ('paths do not exist' unless paths.all? { |p| p.is_a?(URI) || p.exist? }) },
->(paths) { paths && paths.map { |path| path.to_s =~ %r{https?://} ? URI(path) : Pathname(path).expand_path } }

#podspecsnew (readonly)

defaults to ‘self.class.podspecs_from_paths(podspec_paths)`

Returns:

  • (new)

    nil



168
169
170
171
172
173
# File 'lib/cocoapods/generate/configuration.rb', line 168

option :podspecs, ArrayOf.new(Pod::Specification),
'self.class.podspecs_from_paths(podspec_paths)',
nil,
nil,
->(specs) { 'no podspecs found' if specs.empty? },
->(paths) { paths && paths.map { |path| Pathname(path).expand_path } }

#repo_updateBOOLEAN (readonly)

defaults to ‘false`

Returns:

  • (BOOLEAN)

    Force running ‘pod repo update` before install



182
# File 'lib/cocoapods/generate/configuration.rb', line 182

option :repo_update, BOOLEAN, 'false', 'Force running `pod repo update` before install', nil, nil, coerce_to_bool

#share_schemes_for_development_podsBOOLEAN (readonly)

defaults to ‘true`

Returns:

  • (BOOLEAN)

    Whether installation should share schemes for development pods



185
# File 'lib/cocoapods/generate/configuration.rb', line 185

option :share_schemes_for_development_pods, BOOLEAN, 'true', 'Whether installation should share schemes for development pods', nil, nil, coerce_to_bool

#sourcesnew (readonly)

defaults to ‘if use_podfile && podfile then ::Pod::Installer::Analyzer.new(:sandbox, podfile).sources.map(&:url) else pod_config.sources_manager.all.map(&:url) end`

Returns:

  • (new)

    The sources from which to pull dependant pods (defaults to all repos in the podfile if using the podfile, else all available repos). Can be a repo name or URL. Multiple sources must be comma-delimited.



176
177
178
179
180
181
# File 'lib/cocoapods/generate/configuration.rb', line 176

option :sources, ArrayOf.new(String),
'if use_podfile && podfile then ::Pod::Installer::Analyzer.new(:sandbox, podfile).sources.map(&:url) else pod_config.sources_manager.all.map(&:url) end',
'The sources from which to pull dependant pods (defaults to all repos in the podfile if using the podfile, else all available repos). Can be a repo name or URL. Multiple sources must be comma-delimited.',
'SOURCE1,SOURCE2',
->(_) { nil },
->(sources) { Array(sources).flat_map { |s| s.split(',') } }

#use_default_pluginsBOOLEAN (readonly)

defaults to ‘false`

Returns:

  • (BOOLEAN)

    Whether installation should activate default plugins



183
# File 'lib/cocoapods/generate/configuration.rb', line 183

option :use_default_plugins, BOOLEAN, 'false', 'Whether installation should activate default plugins', nil, nil, coerce_to_bool

#use_librariesBOOLEAN (readonly)

defaults to ‘false`

Returns:

  • (BOOLEAN)

    Whether to use libraries instead of frameworks



150
# File 'lib/cocoapods/generate/configuration.rb', line 150

option :use_libraries, BOOLEAN, 'false', 'Whether to use libraries instead of frameworks', nil, nil, coerce_to_bool

#use_lockfileBOOLEAN (readonly)

defaults to ‘!!lockfile`

Returns:

  • (BOOLEAN)

    Whether the lockfile should be used to discover transitive dependencies



147
# File 'lib/cocoapods/generate/configuration.rb', line 147

option :use_lockfile, BOOLEAN, '!!lockfile', 'Whether the lockfile should be used to discover transitive dependencies', nil, nil, coerce_to_bool

#use_lockfile_versionsBOOLEAN (readonly)

defaults to ‘use_lockfile`

Returns:

  • (BOOLEAN)

    Whether versions from the lockfile should be used



148
# File 'lib/cocoapods/generate/configuration.rb', line 148

option :use_lockfile_versions, BOOLEAN, 'use_lockfile', 'Whether versions from the lockfile should be used', nil, nil, coerce_to_bool

#use_modular_headersBOOLEAN (readonly)

defaults to ‘false`

Returns:

  • (BOOLEAN)

    Whether the target should be generated as a clang module, treating dependencies as modules, as if ‘use_modular_headers!` were specified. Will error if both this option and a podfile are specified



187
# File 'lib/cocoapods/generate/configuration.rb', line 187

option :use_modular_headers, BOOLEAN, 'false', 'Whether the target should be generated as a clang module, treating dependencies as modules, as if `use_modular_headers!` were specified. Will error if both this option and a podfile are specified', nil, nil, coerce_to_bool

#use_podfileBOOLEAN (readonly)

defaults to ‘!!podfile`

Returns:

  • (BOOLEAN)

    Whether restrictions should be copied from the podfile



137
# File 'lib/cocoapods/generate/configuration.rb', line 137

option :use_podfile, BOOLEAN, '!!podfile', 'Whether restrictions should be copied from the podfile', nil, nil, coerce_to_bool

#use_podfile_pluginsBOOLEAN (readonly)

defaults to ‘use_podfile`

Returns:

  • (BOOLEAN)

    Whether plugins should be copied from the podfile



138
# File 'lib/cocoapods/generate/configuration.rb', line 138

option :use_podfile_plugins, BOOLEAN, 'use_podfile', 'Whether plugins should be copied from the podfile', nil, nil, coerce_to_bool

#warn_for_multiple_pod_sourcesBOOLEAN (readonly)

defaults to ‘false`

Returns:

  • (BOOLEAN)

    Whether installation should warn when a pod is found in multiple sources



186
# File 'lib/cocoapods/generate/configuration.rb', line 186

option :warn_for_multiple_pod_sources, BOOLEAN, 'false', 'Whether installation should warn when a pod is found in multiple sources', nil, nil, coerce_to_bool

Class Method Details

.from_env(env = ENV) ⇒ Hash<Symbol,Object>

Returns the configuration hash parsed from the env.

Parameters:

  • env (ENV, Hash<String,String>) (defaults to: ENV)

Returns:

  • (Hash<Symbol,Object>)

    the configuration hash parsed from the env



234
235
236
237
238
239
# File 'lib/cocoapods/generate/configuration.rb', line 234

def self.from_env(env = ENV)
  options.each_with_object({}) do |option, config|
    next unless (value = env["COCOAPODS_GENERATE_#{option.name.upcase}"])
    config[option.name] = option.coerce(value)
  end
end

.from_file(path) ⇒ Hash<Symbol,Object>

Returns the configuration hash parsed from the given file.

Parameters:

  • path (Pathname)

Returns:

  • (Hash<Symbol,Object>)

    the configuration hash parsed from the given file

Raises:

  • (Informative)


210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/cocoapods/generate/configuration.rb', line 210

def self.from_file(path)
  raise Informative, "No cocoapods-generate configuration found at #{UI.path path}" unless path.file?
  require 'yaml'
  yaml = YAML.load_file(path)
  unless yaml.is_a?(Hash)
    unless path.read.strip.empty?
      raise Informative, "Hash not found in configuration at #{UI.path path} -- got #{yaml.inspect}"
    end
    yaml = {}
  end
  yaml = yaml.with_indifferent_access

  Dir.chdir(path.dirname) do
    options.each_with_object({}) do |option, config|
      next unless yaml.key?(option.name)
      config[option.name] = option.coerce yaml[option.name]
    end
  end
end

.podspecs_from_paths(paths) ⇒ Array<Specification>

Returns the podspecs found at the given paths. This method will download specs from URLs and traverse a directory’s children.

Parameters:

  • paths (Array<Pathname,URI>)

    the paths to search for podspecs

Returns:

  • (Array<Specification>)

    the podspecs found at the given paths. This method will download specs from URLs and traverse a directory’s children.



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/cocoapods/generate/configuration.rb', line 307

def self.podspecs_from_paths(paths)
  paths = [Pathname('.')] if paths.empty?
  paths.flat_map do |path|
    if path.is_a?(URI)
      require 'cocoapods/open-uri'
      begin
        contents = open(path.to_s).read
      rescue StandardError => e
        next e
      end
      begin
          Pod::Specification.from_string contents, path.to_s
        rescue StandardError
          $ERROR_INFO
        end
    elsif path.directory?
      glob = Pathname.glob(path + '*.podspec{.json,}')
      next StandardError.new "no specs found in #{UI.path path}" if glob.empty?
      glob.map { |f| Pod::Specification.from_file(f) }
    else
      Pod::Specification.from_file(path)
    end
  end
end

Instance Method Details

#==(other) ⇒ Boolean

Returns whether this configuration is equivalent to other.

Returns:

  • (Boolean)

    whether this configuration is equivalent to other



271
272
273
274
# File 'lib/cocoapods/generate/configuration.rb', line 271

def ==(other)
  self.class == other.class &&
    to_h == other.to_h
end

#gen_dir_for_pod(name) ⇒ Pathname

Returns the directory for installation of the generated workspace.

Parameters:

  • name (String)

    the name of the pod

Returns:

  • (Pathname)

    the directory for installation of the generated workspace



291
292
293
# File 'lib/cocoapods/generate/configuration.rb', line 291

def gen_dir_for_pod(name)
  gen_directory.join(name)
end

#to_hHash<Symbol,Object>

Returns a hash where the keys are option names and values are the non-nil set values.

Returns:

  • (Hash<Symbol,Object>)

    a hash where the keys are option names and values are the non-nil set values



261
262
263
264
265
266
267
# File 'lib/cocoapods/generate/configuration.rb', line 261

def to_h
  self.class.options.each_with_object({}) do |option, hash|
    value = send(option.name)
    next if value.nil?
    hash[option.name] = value
  end
end

#to_sString

Returns a string describing the configuration, suitable for UI presentation.

Returns:

  • (String)

    a string describing the configuration, suitable for UI presentation



278
279
280
281
282
283
284
285
# File 'lib/cocoapods/generate/configuration.rb', line 278

def to_s
  hash = to_h
  hash.delete(:pod_config)
  hash.each_with_index.each_with_object('`pod gen` configuration {'.dup) do |((k, v), i), s|
    s << ',' unless i.zero?
    s << "\n" << '  ' << k.to_s << ': ' << v.to_s.gsub(/:0x\h+/, '')
  end << ' }'
end

#use_frameworks?Boolean

Returns whether gen should install with dynamic frameworks.

Returns:

  • (Boolean)

    whether gen should install with dynamic frameworks



297
298
299
# File 'lib/cocoapods/generate/configuration.rb', line 297

def use_frameworks?
  !use_libraries?
end

#validateArray<String>

Returns errors in the configuration.

Returns:

  • (Array<String>)

    errors in the configuration



243
244
245
246
247
248
# File 'lib/cocoapods/generate/configuration.rb', line 243

def validate
  hash = to_h
  self.class.options.map do |option|
    option.validate(hash[option.name])
  end.compact
end

#with_changes(changes) ⇒ Configuration

Returns a new configuration object with the given changes applies.

Parameters:

  • changes (Hash<Symbol,Object>)

Returns:

  • (Configuration)

    a new configuration object with the given changes applies



254
255
256
# File 'lib/cocoapods/generate/configuration.rb', line 254

def with_changes(changes)
  self.class.new(**to_h.merge(changes))
end