class Pod::Generate::Configuration
Constants
- BOOLEAN
- Option
Attributes
@return [Array<Option>]
all of the options available in the configuration
Public Class Methods
@return [Hash<Symbol,Object>] the configuration hash parsed from the env
@param [ENV,Hash<String,String>] env
# File lib/cocoapods/generate/configuration.rb, line 259 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
@return [Hash<Symbol,Object>] the configuration hash parsed from the given file
@param [Pathname] path
@raises [Informative] if the file does not exist or is not a YAML hash
# File lib/cocoapods/generate/configuration.rb, line 235 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
@return [Array<Specification>] the podspecs found at the given paths.
This method will download specs from URLs and traverse a directory's children.
@param [Array<Pathname,URI>] paths
the paths to search for podspecs
@param [Pathname] gen_directory
the directory that the gen installation would occur into.
# File lib/cocoapods/generate/configuration.rb, line 349 def self.podspecs_from_paths(paths, gen_directory) 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.expand_path + '**/*.podspec{.json,}').select { |f| f.relative_path_from(gen_directory).to_s.start_with?('..') } glob.reject! { |f| File.basename(f.dirname) == 'Local Podspecs' && f.parent.parent.join('Manifest.lock').file? } next StandardError.new "no specs found in #{UI.path path}" if glob.empty? podspecs = glob.map { |f| Pod::Specification.from_file(f) } podspecs.group_by(&:name).sort_by(&:first).flat_map do |name, specs| if specs.size != 1 Pod::UI.warn("Multiple podspecs found for pod #{name}, which one will be used is undefined:#{specs.map { |s| "\n - #{s.defined_in_file}" }.join}") end specs end else Pod::Specification.from_file(path) end end end
Private Class Methods
Declares a new option
@!macro [attach] $0
@attribute [r] $1 @return [$2] $4 defaults to `$3`
# File lib/cocoapods/generate/configuration.rb, line 56 def self.option(*args) options << Option.new(*args) end
Public Instance Methods
@return [Boolean] whether this configuration is equivalent to other
# File lib/cocoapods/generate/configuration.rb, line 296 def ==(other) self.class == other.class && to_h == other.to_h end
@return [Pathname] the directory for installation of the generated workspace.
@param [Array<Specification>] specs The specs to get a directory name for.
# File lib/cocoapods/generate/configuration.rb, line 316 def gen_dir_for_specs(specs) basename = specs.count == 1 ? specs.first.name : 'Workspace' gen_directory.join(basename) end
@return [String] The project name to use for generating this workspace.
@param [Array<Specification>] specs
the specifications to generate project name for.
# File lib/cocoapods/generate/configuration.rb, line 332 def project_name_for_specs(specs) project_name = specs.count == 1 ? +specs.first.name.dup : +'Workspace' # When using multiple Xcode project the project name will collide with the actual .xcodeproj meant for the pod # that we are generating the workspace for. project_name << 'Sample' if generate_multiple_pod_projects? && specs.count == 1 project_name end
@return [Hash<Symbol,Object>]
a hash where the keys are option names and values are the non-nil set values
# File lib/cocoapods/generate/configuration.rb, line 286 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
@return [String] a string describing the configuration, suitable for UI presentation
# File lib/cocoapods/generate/configuration.rb, line 303 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
@return [Boolean] whether gen should install with dynamic frameworks
# File lib/cocoapods/generate/configuration.rb, line 323 def use_frameworks? !use_libraries? end
@return [Array<String>] errors in the configuration
# File lib/cocoapods/generate/configuration.rb, line 268 def validate hash = to_h self.class.options.map do |option| option.validate(hash[option.name]) end.compact end
@return [Configuration] a new configuration object with the given changes applies
@param [Hash<Symbol,Object>] changes
# File lib/cocoapods/generate/configuration.rb, line 279 def with_changes(changes) self.class.new(**to_h.merge(changes)) end