Class: Command::Repeating
- Inherits:
 - 
      ArgumentDecoration
      
        
- Object
 - Argument
 - ArgumentDecoration
 - Command::Repeating
 
 
- Defined in:
 - lib/command-set/arguments.rb
 
Overview
Consumes several positions of the decorated argument.
repeating.file_argument :some_files
Will collect an array into some_files of validated files.
Defined Under Namespace
Classes: Omittable
Instance Attribute Summary
Attributes inherited from Argument
Instance Method Summary collapse
- #consume(subject, arguments) ⇒ Object
 - #consume_hash(subject, hash) ⇒ Object
 - #match_terms(subject, terms, arguments) ⇒ Object
 - #merge_hashes(hash, other_hash) ⇒ Object
 
Methods inherited from ArgumentDecoration
#decorated, #initialize, #pretty_print_instance_variables, register
Methods inherited from Argument
#basis, #check_present, #complete, #initialize, #names, #omittable?, #parse, register, #required?, #subject_requirements, #validate
Constructor Details
This class inherits a constructor from Command::ArgumentDecoration
Instance Method Details
#consume(subject, arguments) ⇒ Object
      542 543 544 545 546 547 548  | 
    
      # File 'lib/command-set/arguments.rb', line 542 def consume(subject, arguments) result = {} until arguments.empty? or not validate(arguments.first, subject) do merge_hashes(result, decorated.consume(subject, arguments)) end return result end  | 
  
#consume_hash(subject, hash) ⇒ Object
      528 529 530 531 532 533 534 535 536 537 538 539 540  | 
    
      # File 'lib/command-set/arguments.rb', line 528 def consume_hash(subject, hash) result = [*names].inject({}) do |arg_hash, name| terms = hash[name] if terms.nil? arg_hash else [*terms].inject(arg_hash) do |a_h, term| merge_hashes(a_h, decorated.consume_hash(subject, {name => term})) end end end return result end  | 
  
#match_terms(subject, terms, arguments) ⇒ Object
      550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567  | 
    
      # File 'lib/command-set/arguments.rb', line 550 def match_terms(subject, terms, arguments) old_length = terms.length + 1 middle_arguments = nil while terms.length < old_length and not terms.empty? do middle_arguments = [decorated] old_length = terms.length until middle_arguments.empty? or terms.empty? do middle_arguments.first.match_terms(subject, terms, middle_arguments) end end if(terms.empty? and middle_arguments.empty?) middle_arguments = [Omittable.new(decorated)] end arguments[0,1] = *middle_arguments return true end  | 
  
#merge_hashes(hash, other_hash) ⇒ Object
      569 570 571 572 573 574 575  | 
    
      # File 'lib/command-set/arguments.rb', line 569 def merge_hashes(hash, other_hash) other_hash.each_pair do |name, value| hash[name] ||= [] hash[name] << value end return hash end  |