Class: Git::Commands::OperandAllocator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/git/commands/arguments.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Allocates operand (positional argument) values to definitions following Ruby semantics.

This class handles the complex logic of mapping positional values to their definitions, supporting required, optional, and repeatable operands.

Defined Under Namespace

Classes: LeadingAllocationState

Instance Method Summary collapse

Constructor Details

#initialize(definitions) ⇒ OperandAllocator

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.

Returns a new instance of OperandAllocator.

Parameters:

  • definitions (Array<Hash>)

    operand definitions



3310
3311
3312
# File 'lib/git/commands/arguments.rb', line 3310

def initialize(definitions)
  @definitions = definitions
end

Instance Method Details

#allocate(values) ⇒ Array(Hash, Integer)

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.

Allocate values to definitions

Parameters:

  • values (Array)

    the positional argument values

Returns:

  • (Array(Hash, Integer))

    [allocation_hash, consumed_count]



3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
# File 'lib/git/commands/arguments.rb', line 3317

def allocate(values)
  allocation = {}
  repeatable_index = @definitions.find_index { |d| d[:repeatable] }

  consumed = if repeatable_index.nil?
               allocate_without_repeatable(values, allocation)
             else
               allocate_with_repeatable(values, allocation, repeatable_index)
             end

  [allocation, consumed]
end