I'm working on some gems that assist in web development. Rather than write them for specific web software, like Sinatra or Rails, I created a little class that provides a common interface to common web transaction information.
Right now it's just a little file, 50 lines of code, and it just provides an interface to request parameters. Before I go much further I want to see if there's already something like it out there.
Here's how it works, and will work.
The base class is called CWT (Common Web Transaction). CWT is mostly just an interface. There are subclasses for different web environments, like CWT::Sinatra and CWT::Rack (which could probably be combined into almost the same class.) You instantiate a CWT object of the appropriate class, passing in whatever objects are necessary for that class, such as a Rack::Request object.
Each environment class provides a common set of methods to access common needs. Currently, a CWT object provides a request method that has a hash-like interface. I'm getting ready to provide a session method.
You can then pass that CWT object into utility modules that only need to be written for CWT, instead of specific environments. For example, the module can be written to use the request method without having to deal with the details of how that environment provides request info.
CWT also has a module (not loaded by default) called CWT::Fake which simplifies creating a fake request for command line testing. CWT::Fake provides not only the request method, but also an environment hash with examples of all the usual web transaction properties like HTTP_REMOTE_ADDR and QUERY_STRING.
Is there already something out there like this?
Aucun commentaire:
Enregistrer un commentaire