Class: Command::FiddlyArgument

Inherits:
Argument
  • Object
show all
Defined in:
lib/command-set/arguments.rb

Overview

Using FiddlyArguments is sometimes unavoidable, but it kind of stinks. You assign blocks that validate, complete and parse the input. You’re probably better off subclassing Argument.

n.b. that FiddlyArguments can’t use the subject keyword to use the application state as their basis

Instance Attribute Summary

Attributes inherited from Argument

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Argument

#basis, #check_present, #complete, #consume, #consume_hash, #match_terms, #names, #omittable?, #parse, register, #required?, #subject_requirements, #validate

Constructor Details

#initialize(name, block) ⇒ FiddlyArgument

Returns a new instance of FiddlyArgument.



322
323
324
325
326
# File 'lib/command-set/arguments.rb', line 322

def initialize(name, block)
  super(name, nil)

  (class << self; self; end).class_eval &block
end

Class Method Details

.completion(&block) ⇒ Object

Raises:

  • (TypeError)


328
329
330
331
# File 'lib/command-set/arguments.rb', line 328

def self.completion(&block)
  raise TypeError unless block.arity == 2
  define_method :complete, &block
end

.parser(&block) ⇒ Object

Raises:

  • (TypeError)


338
339
340
341
# File 'lib/command-set/arguments.rb', line 338

def self.parser(&block)
  raise TypeError unless block.arity == 2
  define_method :parse, &block
end

.validation(&block) ⇒ Object

Raises:

  • (TypeError)


333
334
335
336
# File 'lib/command-set/arguments.rb', line 333

def self.validation(&block)
  raise TypeError unless block.arity == 2
  define_method :validate, &block
end