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 243 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 219 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
# File lib/cocoapods/generate/configuration.rb, line 316 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
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 280 def ==(other) self.class == other.class && to_h == other.to_h end
@return [Pathname] the directory for installation of the generated workspace
@param [String] name the name of the pod
# File lib/cocoapods/generate/configuration.rb, line 300 def gen_dir_for_pod(name) gen_directory.join(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 270 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 287 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 306 def use_frameworks? !use_libraries? end
@return [Array<String>] errors in the configuration
# File lib/cocoapods/generate/configuration.rb, line 252 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 263 def with_changes(changes) self.class.new(**to_h.merge(changes)) end