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
@return [Array<Symbol>] The alias names of this parameter
@return [String] The description of this parameter @since 0.6.0
@return [Symbol] The primary name of this parameter
Public Class Methods
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
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
Protected Instance Methods
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
Resets this parameter to its initial state
@since 0.4.0
# File lib/rubikon/parameter.rb, line 68 def reset @active = false end