Class: Bundler::Thor::Arguments

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/vendor/thor/lib/thor/parser/arguments.rb

Overview

:nodoc: # rubocop:disable ClassLength

Direct Known Subclasses

Options

Constant Summary collapse

NUMERIC =
/[-+]?(\d*\.\d+|\d+)/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments = []) ⇒ Arguments

Takes an array of Bundler::Thor::Argument objects.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bundler/vendor/thor/lib/thor/parser/arguments.rb', line 26

def initialize(arguments = [])
  @assigns = {}
  @non_assigned_required = []
  @switches = arguments

  arguments.each do |argument|
    if !argument.default.nil?
      @assigns[argument.human_name] = argument.default
    elsif argument.required?
      @non_assigned_required << argument
    end
  end
end

Class Method Details

.parse(*args) ⇒ Object



19
20
21
22
# File 'lib/bundler/vendor/thor/lib/thor/parser/arguments.rb', line 19

def self.parse(*args)
  to_parse = args.pop
  new(*args).parse(to_parse)
end

.split(args) ⇒ Object

Receives an array of args and returns two arrays, one with arguments and one with switches.



8
9
10
11
12
13
14
15
16
17
# File 'lib/bundler/vendor/thor/lib/thor/parser/arguments.rb', line 8

def self.split(args)
  arguments = []

  args.each do |item|
    break if item.is_a?(String) && item =~ /^-/
    arguments << item
  end

  [arguments, args[Range.new(arguments.size, -1)]]
end

Instance Method Details

#parse(args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/bundler/vendor/thor/lib/thor/parser/arguments.rb', line 40

def parse(args)
  @pile = args.dup

  @switches.each do |argument|
    break unless peek
    @non_assigned_required.delete(argument)
    @assigns[argument.human_name] = send(:"parse_#{argument.type}", argument.human_name)
  end

  check_requirement!
  @assigns
end

#remainingObject



53
54
55
# File 'lib/bundler/vendor/thor/lib/thor/parser/arguments.rb', line 53

def remaining
  @pile
end