Skip to content

Configuring with a Hash

danielwellman edited this page Aug 18, 2012 · 1 revision

Deprecation Notice!

As of Bane version 0.3, configuration via a Hash is deprecated. Instead of using the Configuration() method as described below, please directly instantiate a BehaviorServer with the required arguments. This class is being deprecated and removed because the flexibility of the code creates a structure that is harder to read and maintain. I'm also not sure anyone is using this method -- if so, please open a GitHub Issue and let me know if you're using it -- and if so, how.

For examples of how to configure Bane programmatically, see the examples folder in the project source.

The original documentation for versions prior to 0.3 appears below.


If you wish to override the defaults provided by behaviors (such as the message sent in the FixedResponse) or wish to start up a single instance of Bane using a discontinuous port range (such as running behaviors on port 3030 and 8080), you must configure bane using a Hash.

The Laucher constructor requires an instance of class Configuration. Use the Configuration helper method to create an instance of the Configuration and pass a hash like so:

launcher = Launcher.new(Configuration(
     3000 => {:behavior => FixedResponse, :message => "Shall we play a game?"},
   )
)

The above configuration will start the FixedResponse server on port 3000 and respond with the message "Shall we play a game?"

The hash should contain keys for the desired port number and the value should be a hash describing the behavior. At least one entry is required: a key (the symbol :behavior) and a value of the class name of the behavior to use. All other options should be passed in this hash. For a description of the supported options for each behavior, see the class RDoc.