Class: Git::Commands::OperandAllocator::LeadingAllocationState 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.

Encapsulates state for allocating leading positionals

Instance Method Summary collapse

Constructor Details

#initialize(definitions, values, required_check)

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.

Initialize allocation state for the given leading definitions and values

Parameters:

  • definitions (Array<Hash>)

    the leading operand definitions

  • values (Array)

    the values available for allocation

  • required_check (Method)

    callable returning true if a definition is required



4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
# File 'lib/git/commands/arguments.rb', line 4431

def initialize(definitions, values, required_check)
  @definitions = definitions
  @values = values
  @required_check = required_check
  @required_count = definitions.count { |d| required_check.call(d) }
  @extra_for_optionals = [values.size - @required_count, 0].max
  @val_idx = 0
  @opt_idx = 0
  @consumed = 0
end

Instance Method Details

#allocate(allocation) ⇒ 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.

Allocates leading positional values and returns consumed non-nil count

Parameters:

  • allocation (Hash{Symbol => Object})

    allocation hash to populate

Returns:

  • (Integer)

    number of non-nil positional values consumed



4448
4449
4450
4451
# File 'lib/git/commands/arguments.rb', line 4448

def allocate(allocation)
  @definitions.each { |definition| allocate_one(allocation, definition) }
  @consumed
end