Class: UserChoices::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/user-choices/command.rb

Overview

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).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommand

Returns a new instance of Command.



10
11
12
13
14
15
16
# 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

Instance Attribute Details

#user_choicesObject (readonly)

Returns the value of attribute user_choices.



8
9
10
# File 'lib/user-choices/command.rb', line 8

def user_choices
  @user_choices
end

Instance Method Details

#add_choices(builder) ⇒ Object

Add choices to the ChoicesBuilder. A choice is a symbol that ends up in the as an OptionParser-style description of command-line arguments.

Must be defined in a subclass.



29
# File 'lib/user-choices/command.rb', line 29

def add_choices(builder); subclass_responsibility; end

#add_sources(builder) ⇒ Object

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

Must be defined in a subclass.



22
# File 'lib/user-choices/command.rb', line 22

def add_sources(builder); subclass_responsibility; end

#executeObject

Execute the command, using @user_choices for parameterization.

Must be defined in a subclass.



40
# File 'lib/user-choices/command.rb', line 40

def execute; subclass_responsibility; end

#postprocess_user_choicesObject

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



34
35
# File 'lib/user-choices/command.rb', line 34

def postprocess_user_choices
end