Class: Bundler::Thor::Arguments
- Inherits:
-
Object
- Object
- Bundler::Thor::Arguments
- Defined in:
- lib/bundler/vendor/thor/lib/thor/parser/arguments.rb
Overview
:nodoc: # rubocop:disable ClassLength
Direct Known Subclasses
Constant Summary collapse
- NUMERIC =
/[-+]?(\d*\.\d+|\d+)/
Class Method Summary collapse
- .parse(*args) ⇒ Object
-
.split(args) ⇒ Object
Receives an array of args and returns two arrays, one with arguments and one with switches.
Instance Method Summary collapse
-
#initialize(arguments = []) ⇒ Arguments
constructor
Takes an array of Bundler::Thor::Argument objects.
- #parse(args) ⇒ Object
- #remaining ⇒ Object
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 39 40 41 42 |
# 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? begin @assigns[argument.human_name] = argument.default.dup rescue TypeError # Compatibility shim for un-dup-able Fixnum in Ruby < 2.4 @assigns[argument.human_name] = argument.default end 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
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/bundler/vendor/thor/lib/thor/parser/arguments.rb', line 44 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 |
#remaining ⇒ Object
57 58 59 |
# File 'lib/bundler/vendor/thor/lib/thor/parser/arguments.rb', line 57 def remaining @pile end |