Class: Command::ProcArgument
- Defined in:
- lib/command-set/arguments.rb
Overview
Created with a two argument block, a proc_argument validates it’s input by passing it to the block. It also uses the block to validate.
As a result, the block should return a list of acceptable completions, given a prefix and the current subject.
Ideally, use proc_arguments to prototype new argument types before creating whole classes for them.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Argument
Instance Method Summary collapse
- #complete(terms, prefix, subject) ⇒ Object
-
#initialize(name, prok) ⇒ ProcArgument
constructor
A new instance of ProcArgument.
- #validate(term, subject) ⇒ Object
Methods inherited from Argument
#basis, #check_present, #consume, #consume_hash, #match_terms, #names, #omittable?, #parse, register, #required?, #subject_requirements
Constructor Details
#initialize(name, prok) ⇒ ProcArgument
Returns a new instance of ProcArgument.
394 395 396 397 398 |
# File 'lib/command-set/arguments.rb', line 394 def initialize(name, prok) raise TypeError, "Block not arity 2: #{prok.arity}" unless prok.arity == 2 super(name, nil) @process = proc &prok end |
Instance Method Details
#complete(terms, prefix, subject) ⇒ Object
400 401 402 |
# File 'lib/command-set/arguments.rb', line 400 def complete(terms, prefix, subject) return @process.call(prefix, subject) end |
#validate(term, subject) ⇒ Object
404 405 406 |
# File 'lib/command-set/arguments.rb', line 404 def validate(term, subject) return @process.call(term, subject).include?(term) end |