Class: Git::ConfigEntryInfo

Inherits:
Data
  • Object
show all
Defined in:
lib/git/config_entry_info.rb

Overview

Represents a single Git configuration entry

Returned by Configuring read operations such as Git::Configuring#config_get, Git::Configuring#config_get_all, Git::Configuring#config_list, and their related methods.

Examples:

Create a ConfigEntryInfo

entry = Git::ConfigEntryInfo.new(
  scope: 'local',
  origin: 'file:.git/config',
  key: 'remote.origin.url',
  value: 'https://github.com/ruby-git/ruby-git'
)
entry.section    # => "remote"
entry.subsection # => "origin"
entry.variable   # => "url"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key

Returns:

  • (Object)

    the current value of key



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/git/config_entry_info.rb', line 58

ConfigEntryInfo = Data.define(:scope, :origin, :key, :value) do
  # Returns the section component of the key (everything before the first dot)
  #
  # Returns an empty string when the key contains no dot.
  #
  # @example Section component of a dotted key
  #   entry.section # => "remote"
  #
  # @return [String] the section name, or an empty string when the key has no dot
  #
  def section = first_dot ? key[0...first_dot] : ''

  # Returns the subsection component of the key (everything between the first and last dot)
  #
  # Returns an empty string when the key has zero or one dot (no subsection).
  #
  # @example Subsection component of a dotted key
  #   entry.subsection # => "origin"
  #
  # @return [String] the subsection name, or an empty string when there is no subsection
  #
  def subsection = first_dot && first_dot != last_dot ? key[(first_dot + 1)...last_dot] : ''

  # Returns the variable component of the key (everything after the last dot)
  #
  # Returns the full key when the key contains no dot.
  #
  # @example Variable component of a dotted key
  #   entry.variable # => "url"
  #
  # @return [String] the variable name (everything after the last dot)
  #
  def variable = last_dot ? key[(last_dot + 1)..] : key

  private

  # Returns the index of the first dot in the key, or nil if none exists
  #
  # @return [Integer, nil] the zero-based index of the first dot, or `nil`
  #
  def first_dot = key.index('.')

  # Returns the index of the last dot in the key, or nil if none exists
  #
  # @return [Integer, nil] the zero-based index of the last dot, or `nil`
  #
  def last_dot = key.rindex('.')
end

#originObject (readonly)

Returns the value of attribute origin

Returns:

  • (Object)

    the current value of origin



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/git/config_entry_info.rb', line 58

ConfigEntryInfo = Data.define(:scope, :origin, :key, :value) do
  # Returns the section component of the key (everything before the first dot)
  #
  # Returns an empty string when the key contains no dot.
  #
  # @example Section component of a dotted key
  #   entry.section # => "remote"
  #
  # @return [String] the section name, or an empty string when the key has no dot
  #
  def section = first_dot ? key[0...first_dot] : ''

  # Returns the subsection component of the key (everything between the first and last dot)
  #
  # Returns an empty string when the key has zero or one dot (no subsection).
  #
  # @example Subsection component of a dotted key
  #   entry.subsection # => "origin"
  #
  # @return [String] the subsection name, or an empty string when there is no subsection
  #
  def subsection = first_dot && first_dot != last_dot ? key[(first_dot + 1)...last_dot] : ''

  # Returns the variable component of the key (everything after the last dot)
  #
  # Returns the full key when the key contains no dot.
  #
  # @example Variable component of a dotted key
  #   entry.variable # => "url"
  #
  # @return [String] the variable name (everything after the last dot)
  #
  def variable = last_dot ? key[(last_dot + 1)..] : key

  private

  # Returns the index of the first dot in the key, or nil if none exists
  #
  # @return [Integer, nil] the zero-based index of the first dot, or `nil`
  #
  def first_dot = key.index('.')

  # Returns the index of the last dot in the key, or nil if none exists
  #
  # @return [Integer, nil] the zero-based index of the last dot, or `nil`
  #
  def last_dot = key.rindex('.')
end

#scopeObject (readonly)

Returns the value of attribute scope

Returns:

  • (Object)

    the current value of scope



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/git/config_entry_info.rb', line 58

ConfigEntryInfo = Data.define(:scope, :origin, :key, :value) do
  # Returns the section component of the key (everything before the first dot)
  #
  # Returns an empty string when the key contains no dot.
  #
  # @example Section component of a dotted key
  #   entry.section # => "remote"
  #
  # @return [String] the section name, or an empty string when the key has no dot
  #
  def section = first_dot ? key[0...first_dot] : ''

  # Returns the subsection component of the key (everything between the first and last dot)
  #
  # Returns an empty string when the key has zero or one dot (no subsection).
  #
  # @example Subsection component of a dotted key
  #   entry.subsection # => "origin"
  #
  # @return [String] the subsection name, or an empty string when there is no subsection
  #
  def subsection = first_dot && first_dot != last_dot ? key[(first_dot + 1)...last_dot] : ''

  # Returns the variable component of the key (everything after the last dot)
  #
  # Returns the full key when the key contains no dot.
  #
  # @example Variable component of a dotted key
  #   entry.variable # => "url"
  #
  # @return [String] the variable name (everything after the last dot)
  #
  def variable = last_dot ? key[(last_dot + 1)..] : key

  private

  # Returns the index of the first dot in the key, or nil if none exists
  #
  # @return [Integer, nil] the zero-based index of the first dot, or `nil`
  #
  def first_dot = key.index('.')

  # Returns the index of the last dot in the key, or nil if none exists
  #
  # @return [Integer, nil] the zero-based index of the last dot, or `nil`
  #
  def last_dot = key.rindex('.')
end

#valueObject (readonly)

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/git/config_entry_info.rb', line 58

ConfigEntryInfo = Data.define(:scope, :origin, :key, :value) do
  # Returns the section component of the key (everything before the first dot)
  #
  # Returns an empty string when the key contains no dot.
  #
  # @example Section component of a dotted key
  #   entry.section # => "remote"
  #
  # @return [String] the section name, or an empty string when the key has no dot
  #
  def section = first_dot ? key[0...first_dot] : ''

  # Returns the subsection component of the key (everything between the first and last dot)
  #
  # Returns an empty string when the key has zero or one dot (no subsection).
  #
  # @example Subsection component of a dotted key
  #   entry.subsection # => "origin"
  #
  # @return [String] the subsection name, or an empty string when there is no subsection
  #
  def subsection = first_dot && first_dot != last_dot ? key[(first_dot + 1)...last_dot] : ''

  # Returns the variable component of the key (everything after the last dot)
  #
  # Returns the full key when the key contains no dot.
  #
  # @example Variable component of a dotted key
  #   entry.variable # => "url"
  #
  # @return [String] the variable name (everything after the last dot)
  #
  def variable = last_dot ? key[(last_dot + 1)..] : key

  private

  # Returns the index of the first dot in the key, or nil if none exists
  #
  # @return [Integer, nil] the zero-based index of the first dot, or `nil`
  #
  def first_dot = key.index('.')

  # Returns the index of the last dot in the key, or nil if none exists
  #
  # @return [Integer, nil] the zero-based index of the last dot, or `nil`
  #
  def last_dot = key.rindex('.')
end

Instance Method Details

#sectionString

Returns the section component of the key (everything before the first dot)

Returns an empty string when the key contains no dot.

Examples:

Section component of a dotted key

entry.section # => "remote"

Returns:

  • (String)

    the section name, or an empty string when the key has no dot



68
# File 'lib/git/config_entry_info.rb', line 68

def section = first_dot ? key[0...first_dot] : ''

#subsectionString

Returns the subsection component of the key (everything between the first and last dot)

Returns an empty string when the key has zero or one dot (no subsection).

Examples:

Subsection component of a dotted key

entry.subsection # => "origin"

Returns:

  • (String)

    the subsection name, or an empty string when there is no subsection



79
# File 'lib/git/config_entry_info.rb', line 79

def subsection = first_dot && first_dot != last_dot ? key[(first_dot + 1)...last_dot] : ''

#variableString

Returns the variable component of the key (everything after the last dot)

Returns the full key when the key contains no dot.

Examples:

Variable component of a dotted key

entry.variable # => "url"

Returns:

  • (String)

    the variable name (everything after the last dot)



90
# File 'lib/git/config_entry_info.rb', line 90

def variable = last_dot ? key[(last_dot + 1)..] : key