Module: Camping
- Defined in:
- lib/camping-unabridged.rb,
lib/camping.rb,
lib/camping/ar.rb,
lib/camping/session.rb,
lib/camping/reloader.rb
Overview
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::Controllers is where your controllers live.
-
Camping::Models is where your models live.
-
Camping::Views is where your views live.
-
Camping::Base is a module which is included in all your controllers.
-
Camping::Helpers is a module with useful helpers, both for the controllers and the views. You should fill this up with your own helpers.
Camping also ships with:
-
Camping::Session adds states to your app.
-
Camping::Server starts up your app in development.
-
Camping::Reloader automatically reloads your apps when a file has changed.
More importantly, Camping also installs The Camping Server, please see Camping::Server.
Defined Under Namespace
Modules: Base, Controllers, Helpers, Models, Session, Views Classes: H, Reloader, Server
Constant Summary collapse
- C =
self
- S =
IO.read(__FILE__) rescue nil
- P =
"<h1>Cam\ping Problem!</h1><h2>%s</h2>"
- U =
Rack::Utils
- Apps =
[]
- X =
Controllers
Class Method Summary collapse
-
.call(e) ⇒ Object
Ruby web servers use this method to enter the Camping realm.
-
.goes(m) ⇒ Object
When you are running many applications, you may want to create independent modules for each Camping application.
-
.method_missing(m, c, *a) ⇒ Object
The Camping scriptable dispatcher.
-
.use(*a, &b) ⇒ Object
Injects a middleware:.
Class Method Details
.call(e) ⇒ Object
Ruby web servers use this method to enter the Camping realm. The e
argument is the environment variables hash as per the Rack specification. And array with [status, headers, body] is expected at the output.
584 585 586 |
# File 'lib/camping-unabridged.rb', line 584 def call e;X.M;p=e['PATH_INFO']=U.unescape(e['PATH_INFO']) k,m,*a=X.D p,e['REQUEST_METHOD'].downcase;k.new(e,m).service(*a).to_a;rescue r500(:I,k,m,$!,:env=>e).to_a;end |
.goes(m) ⇒ Object
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.
575 576 |
# File 'lib/camping-unabridged.rb', line 575 def goes m;Apps<<eval(S.gsub(/Camping/,m.to_s), TOPLEVEL_BINDING) end |
.method_missing(m, c, *a) ⇒ Object
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'} ...>
611 612 613 |
# File 'lib/camping-unabridged.rb', line 611 def method_missing m,c,*a;X.M;h=Hash===a[-1]? a.pop: {};e=H[Rack::MockRequest.env_for('',h.delete(:env)||{})];k=X.const_get(c ).new(e,m.to_s);h.each{|i,v|k.send"#{i}=",v};k.service(*a);end |
.use(*a, &b) ⇒ Object
Injects a middleware:
module Blog
use Rack::MethodOverride
use Rack::Session::Memcache, :key => "session"
end
626 627 |
# File 'lib/camping-unabridged.rb', line 626 def use*a,&b;m=a. shift.new(method(:call),*a,&b);(:call){|e|m.call(e)}end |