module Rubikon::Parameter

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.

@author Sebastian Staudt @see Command @see Flag @see Option @since 0.3.0

Attributes

aliases[R]

@return [Array<Symbol>] The alias names of this parameter

description[RW]

@return [String] The description of this parameter @since 0.6.0

name[R]

@return [Symbol] The primary name of this parameter

Public Class Methods

new(app, name, &block) click to toggle source

Creates a new parameter with the given name

@param [Application::Base] app The application this parameter belongs to @param [Symbol, to_sym] name The name of the parameter @param [Proc] block An optional code block to be executed if this

parameter is used
# 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

Public Instance Methods

active?() click to toggle source

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

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

# File lib/rubikon/parameter.rb, line 49
def active?
  @active
end
Also aliased as: given?
given?()
Alias for: active?

Protected Instance Methods

active!() click to toggle source

Marks this parameter as active when it has been supplied by the user on the command-line. This also calls the code block of the parameter if it exists

# File lib/rubikon/parameter.rb, line 59
def active!
  @active = true
  Application::InstanceMethods.instance_method(:sandbox).bind(@app).call.
    instance_eval(&@block) unless @block.nil?
end
reset() click to toggle source

Resets this parameter to its initial state

@since 0.4.0

# File lib/rubikon/parameter.rb, line 68
def reset
  @active = false
end