class UserChoices::Command

A template class. Subclasses describe all the choices a user may make to affect the execution of the command, and the sources for those choices (such as the command line).

Attributes

user_choices[R]

Public Instance Methods

add_choices(builder) click to toggle source

Add choices to the ChoicesBuilder. A choice is a symbol that ends up in the @#user_choices hash. It may have a :default value and a :type, as well as an OptionParser-style description of command-line arguments.

Must be defined in a subclass.

# File lib/user-choices/command.rb, line 29
def add_choices(builder); subclass_responsibility; end
add_sources(builder) click to toggle source

Add sources such as EnvironmentSource, XmlConfigFileSource, and CommandLineSource to the ChoicesBuilder.

Must be defined in a subclass.

# File lib/user-choices/command.rb, line 22
def add_sources(builder); subclass_responsibility; end
execute() click to toggle source

Execute the command, using @#user_choices for parameterization.

Must be defined in a subclass.

# File lib/user-choices/command.rb, line 40
def execute; subclass_responsibility; end
postprocess_user_choices() click to toggle source

After choices from all sources are collected into @#user_choices, this method is called to do any postprocessing. Does nothing unless overridden.

# File lib/user-choices/command.rb, line 34
def postprocess_user_choices
end

Public Class Methods

new() click to toggle source
# File lib/user-choices/command.rb, line 10
def initialize
  builder = ChoicesBuilder.new
  add_sources(builder)
  add_choices(builder)
  @user_choices = builder.build
  postprocess_user_choices
end