Creating a class for carrying out rails commands.

This class encapsulates a lot of logic that wasn't very object oriented.
Helper methods have been created to try to make things more logical and
easy to read.
Merge pull request #11355 from wangjohn/class_for_rails_commands

Creating a class for carrying out rails commands.