Rails on Needle

This is a proof-of-concept implementation of how Needle might be used by Rails.

The following source files replace all files in an applications config/environments directory. No other changes are necessary.

A quick explanation: Rails::Environment encapsulates all environmental issues in Rails. This includes the creation of a Needle registry and adding various services to it. These services include the active environment ("production", "test", etc.) as well as the database configuration, the log file being written to, and so forth.

In addition, all Base classes (ie, ActiveRecord::Base, ActionController::Base, etc.) are dynamically modified to include a reference to a registry, so that applications can easily be wired together and dependency injected. Also, this implementation also has ActiveRecord::Base automatically add subclasses to the registry, so that controllers and so forth can be decoupled from the model implementation with very little effort.

Consider:

      # in the model
      class Author < ActiveRecord::Base
        ...
      end
    
      # in the controller
      class AuthorsController < ActionController::Base
        ...
        def list
          @authors = registry.author.find_all
        end
        ...
      end
    

Among other things, this approach would allow controllers to be tested independently of the models, by injecting a mock AR object into the registry referenced by the controller. Thus, you can teset controllers without needing a database connection, making it easier to design test cases for each nuance of your data.