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

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

Parameters:

  • attrs (Hash)

    accumulator of RemoteInfo keyword arguments

  • variable (String)

    git config variable name (e.g. 'url', 'tagopt')

  • value (String)

    raw config value



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

Parameters:

  • remote_name (String)
  • pairs (Array)

    variable/value pairs collected from config entries

Returns:



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

Parameters:

  • variable (String)

    the config variable name (for error messages)

  • value (String)

    the raw string value from git config

Returns:

  • (Boolean)

    true or false

Raises:

  • (ArgumentError)

    if the value is not a recognized 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

Parameters:

Returns:

  • (Hash{String => Array})

    remote name to 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.

Parameters:

  • config_entries (Array<Git::ConfigEntryInfo>)

    all config entries to inspect; may contain non-remote entries

Returns:

  • (Array<Git::RemoteInfo>)

    one entry per unique remote name, in the order the first entry for each name appeared in config_entries

Raises:

  • (ArgumentError)

    if a boolean config field carries an unrecognized value (mirrors git's own fatal-error behavior)



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