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