Sha256: c08c6a5685d6d36f7fc731f92e672893d724369e37ea87d5346103f5a1094304
Contents?: true
Size: 1.33 KB
Versions: 8
Compression:
Stored size: 1.33 KB
Contents
module UserChoices # 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). class Command attr_reader :user_choices def initialize builder = ChoicesBuilder.new add_sources(builder) add_choices(builder) @user_choices = builder.build postprocess_user_choices end # Add sources such as EnvironmentSource, XmlConfigFileSource, # and CommandLineSource to the ChoicesBuilder. # # Must be defined in a subclass. def add_sources(builder); subclass_responsibility; 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. def add_choices(builder); 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. def postprocess_user_choices end # Execute the command, using @user_choices for parameterization. # # Must be defined in a subclass. def execute; subclass_responsibility; end end end
Version data entries
8 entries across 8 versions & 1 rubygems