Module | Camping |
In: |
lib/camping/ar.rb
lib/camping/reloader.rb lib/camping/server.rb lib/camping/session.rb lib/camping-unabridged.rb |
If you‘re new to Camping, you should probably start by reading the first chapters of The Camping Book.
Okay. So, the important thing to remember is that Camping.goes :Nuts copies the Camping module into Nuts. This means that you should never use any of these methods/classes on the Camping module, but rather on your own app. Here‘s a short explanation on how Camping is organized:
Camping also ships with:
More importantly, Camping also installs The Camping Server, please see Camping::Server.
C | = | self |
S | = | IO.read(__FILE__) rescue nil |
P | = | "<h1>Cam\ping Problem!</h1><h2>%s</h2>" |
U | = | Rack::Utils |
O | = | {} |
Apps | = | [] |
X | = | Controllers |
When you are running many applications, you may want to create independent modules for each Camping application. Camping::goes defines a toplevel constant with the whole MVC rack inside:
require 'camping' Camping.goes :Nuts module Nuts::Controllers; ... end module Nuts::Models; ... end module Nuts::Views; ... end
All the applications will be available in Camping::Apps.
The Camping scriptable dispatcher. Any unhandled method call to the app module will be sent to a controller class, specified as an argument.
Blog.get(:Index) #=> #<Blog::Controllers::Index ... >
The controller object contains all the @cookies, @body, @headers, etc. formulated by the response.
You can also feed environment variables and query variables as a hash, the final argument.
Blog.post(:Login, :input => {'username' => 'admin', 'password' => 'camping'}) #=> #<Blog::Controllers::Login @user=... > Blog.get(:Info, :env => {'HTTP_HOST' => 'wagon'}) #=> #<Blog::Controllers::Info @headers={'HTTP_HOST'=>'wagon'} ...>