snusnu/substation — pull request #10 by snusnu (2013-07-30 02:31:56+00:00)
Title: Refactor Chain::DSL for use with instances of itself

It always bugged me that `Environment` needed to get the `registry` and `chain_dsl` injected separately when it feels like `chain_dsl` should know the registry. Also, it kinda bugged me that a new `Chain::DSL` subclass was created for every environment.

The real reason tho, is that with moving `registry` access inside a `chain_dsl` instance, `Environment#initialize` can be changed to only accept `chain_dsl` (for now). This will "open up 2 more slots" for parameters to `#initialize` - i like 3 params at most). In the future, I will then inject a mutable action registry and the application environment into `Environment#initialize`, in addition to `chain_dsl`.

This will eventually allow for decentralized dispatch table definition, by providing something like `Environment#chain(name, other = Chain::EMPTY, &block)` where `name` will be used to register the created chain with the mutable registry. Furthermore, `Environment#dispatcher` will need no more parameters, as the populated dispatch table (the action registry) as well as the application environment, will already be available inside an `Environment` instance. It is safe to assume that the (user provided) application environment object is already loaded at the time `Substation::Environment` gets instantiated. This is because the app environment is part of the app, which by itself, should know nothing about substation anyway.