Creating a class to build the default middleware stack.

A lot of logic for building the default middleware stack is currently kept in ``Rails::Application`` class, but this can be encapsulated and made more modular by being moved to its own class. Also refactored a couple of the helper methods.