Class: Thor::Arguments
- Inherits:
-
Object
- Object
- Thor::Arguments
- Defined in:
- lib/thor/parser/arguments.rb
Overview
:nodoc:
Direct Known Subclasses
Constant Summary
- NUMERIC =
/(\d*\.\d+|\d+)/
Class Method Summary (collapse)
- + (Object) parse(*args)
-
+ (Object) split(args)
Receives an array of args and returns two arrays, one with arguments and one with switches.
Instance Method Summary (collapse)
-
- (Arguments) initialize(arguments = [])
constructor
Takes an array of Thor::Argument objects.
- - (Object) parse(args)
- - (Object) remaining
Constructor Details
- (Arguments) initialize(arguments = [])
Takes an array of Thor::Argument objects.
26 27 28 29 30 31 32 33 34 35 36 37 |
# 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 elsif argument.required? @non_assigned_required << argument end end end |
Class Method Details
+ (Object) parse(*args)
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 |
+ (Object) split(args)
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 =~ /^-/ arguments << item end return arguments, args[Range.new(arguments.size, -1)] end |
Instance Method Details
- (Object) parse(args)
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/thor/parser/arguments.rb', line 39 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 |
- (Object) remaining
52 53 54 |
# File 'lib/thor/parser/arguments.rb', line 52 def remaining @pile end |