Class: Thor::Arguments
- Inherits:
-
Object
- Object
- Thor::Arguments
- Defined in:
- lib/thor/parser/arguments.rb
Overview
:nodoc:
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 Thor::Argument objects.
- #parse(args) ⇒ Object
- #remaining ⇒ Object
Constructor Details
#initialize(arguments = []) ⇒ Arguments
Takes an array of Thor::Argument objects.
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File '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.dup elsif argument.required? @non_assigned_required << argument end end end |
Class Method Details
.parse(*args) ⇒ Object
19 20 21 22 |
# File '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/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/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 |
#remaining ⇒ Object
53 54 55 |
# File 'lib/thor/parser/arguments.rb', line 53 def remaining @pile end |