Module: Rubikon::Parameter

Included in:
Flag, HasArguments
Defined in:
lib/rubikon/parameter.rb

Overview

A parameter is any command-line argument given to the application that is not prefixed with one or two dashes. Once a parameter is supplied by the user, it is relayed to the command it belongs to.

See Also:

Author:

  • Sebastian Staudt

Since:

  • 0.3.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#aliasesArray<Symbol> (readonly)

Returns The alias names of this parameter.

Returns:

  • (Array<Symbol>)

    The alias names of this parameter

Since:

  • 0.3.0



20
21
22
# File 'lib/rubikon/parameter.rb', line 20

def aliases
  @aliases
end

#descriptionString

Returns The description of this parameter.

Returns:

  • (String)

    The description of this parameter

Since:

  • 0.6.0



24
25
26
# File 'lib/rubikon/parameter.rb', line 24

def description
  @description
end

#nameSymbol (readonly)

Returns The primary name of this parameter.

Returns:

  • (Symbol)

    The primary name of this parameter

Since:

  • 0.3.0



27
28
29
# File 'lib/rubikon/parameter.rb', line 27

def name
  @name
end

Instance Method Details

#active?Boolean Also known as: given?

Returns whether this parameter has is active, i.e. it has been supplied by the user on the command-line

Returns:

  • (Boolean)

    true if this parameter has been supplied on the command-line

Since:

  • 0.3.0



49
50
51
# File 'lib/rubikon/parameter.rb', line 49

def active?
  @active
end

#initialize(app, name, &block) ⇒ Object

Creates a new parameter with the given name

Parameters:

  • app (Application::Base)

    The application this parameter belongs to

  • name (Symbol, #to_sym)

    The name of the parameter

  • block (Proc)

    An optional code block to be executed if this parameter is used

Raises:

  • (ArgumentError)

Since:

  • 0.3.0



35
36
37
38
39
40
41
42
43
# File 'lib/rubikon/parameter.rb', line 35

def initialize(app, name, &block)
  raise ArgumentError unless app.is_a? Application::Base

  @active  = false
  @aliases = []
  @app     = app
  @block   = block
  @name    = name.to_sym
end