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.

Instance Attribute Summary

Attributes inherited from Argument

#name, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Argument

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

Constructor Details

#initialize(name, &block) ⇒ FiddlyArgument

Returns a new instance of FiddlyArgument.



290
291
292
293
294
# File 'lib/command-set/arguments.rb', line 290

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

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

Class Method Details

.completion(&block) ⇒ Object

Raises:

  • (TypeError)


296
297
298
299
# File 'lib/command-set/arguments.rb', line 296

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

.parser(&block) ⇒ Object

Raises:

  • (TypeError)


307
308
309
310
# File 'lib/command-set/arguments.rb', line 307

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

.validation(&block) ⇒ Object

Raises:

  • (TypeError)


302
303
304
305
# File 'lib/command-set/arguments.rb', line 302

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