Module: Git::Parsers::Remote Private
- Defined in:
- lib/git/parsers/remote.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Parser that builds RemoteInfo objects from git config entries
Accepts Array<Git::ConfigEntryInfo> as returned by
Configuring#config_list and groups entries by remote name,
collecting multi-value fields and coercing boolean values.
Class Method Summary collapse
-
.apply_pair(attrs, variable, value)
private
Apply a single variable/value pair to an attrs hash.
-
.build_remote_info(remote_name, pairs) ⇒ Git::RemoteInfo
private
Build a RemoteInfo from grouped variable/value pairs.
-
.coerce_boolean(variable, value) ⇒ Boolean
private
Coerce a git config boolean string to a Ruby boolean.
-
.group_by_remote(config_entries) ⇒ Hash{String => Array}
private
Group config entries by remote name, collecting variable/value pairs.
-
.parse_list(config_entries) ⇒ Array<Git::RemoteInfo>
private
Parse an array of config entries into an array of RemoteInfo objects.
Class Method Details
.apply_pair(attrs, variable, value)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Apply a single variable/value pair to an attrs hash
126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/git/parsers/remote.rb', line 126 def apply_pair(attrs, variable, value) field = VARIABLE_TO_FIELD[variable] return unless field # ignore unknown variables if ARRAY_VARIABLES.include?(variable) attrs[field] ||= [] attrs[field] << value elsif BOOLEAN_VARIABLES.include?(variable) attrs[field] = coerce_boolean(variable, value) else attrs[field] = value end end |
.build_remote_info(remote_name, pairs) ⇒ Git::RemoteInfo
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build a RemoteInfo from grouped variable/value pairs
108 109 110 111 112 |
# File 'lib/git/parsers/remote.rb', line 108 def build_remote_info(remote_name, pairs) attrs = { name: remote_name } pairs.each { |variable, value| apply_pair(attrs, variable, value) } Git::RemoteInfo.new(**attrs) end |
.coerce_boolean(variable, value) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Coerce a git config boolean string to a Ruby boolean
152 153 154 155 156 157 158 159 |
# File 'lib/git/parsers/remote.rb', line 152 def coerce_boolean(variable, value) normalized = value.downcase return true if BOOL_TRUE_VALUES.include?(normalized) || normalized == '' return false if BOOL_FALSE_VALUES.include?(normalized) raise ArgumentError, "unrecognized boolean value #{value.inspect} for config variable #{variable.inspect}" end |
.group_by_remote(config_entries) ⇒ Hash{String => Array}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Group config entries by remote name, collecting variable/value pairs
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/git/parsers/remote.rb', line 48 def group_by_remote(config_entries) config_entries.each_with_object({}) do |entry, groups| next unless entry.section == 'remote' && !entry.subsection.empty? remote_name = entry.subsection variable = entry.variable.downcase groups[remote_name] ||= [] groups[remote_name] << [variable, entry.value] end end |
.parse_list(config_entries) ⇒ Array<Git::RemoteInfo>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parse an array of config entries into an array of RemoteInfo objects
Groups entries whose key matches remote.<name>.<variable> by remote
name and builds one RemoteInfo per unique remote name.
Non-remote config entries (keys that do not start with remote.) are
silently ignored.
36 37 38 |
# File 'lib/git/parsers/remote.rb', line 36 def parse_list(config_entries) group_by_remote(config_entries).map { |name, pairs| build_remote_info(name, pairs) } end |