Skip to content

Commit

Permalink
Add Camping.use
Browse files Browse the repository at this point in the history
  • Loading branch information
judofyr committed Jun 11, 2009
1 parent 5b27ca1 commit 0d21c24
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions lib/camping-unabridged.rb
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,17 @@ def method_missing(m, c, *a)
k.send("input=", h[:input]) if h[:input]
k.service(*a)
end
# Injects a middleware:
#
# module Blog
# use Rack::MethodOverride
# use Rack::Session::Memcache, :key => "session"
# end
def use(*a)
m = a.shift.new(method(:call), *a)
meta_def(:call) { |e| m.call(e) }
end
end
# Views is an empty module for storing methods which create HTML. The HTML
Expand Down
3 changes: 2 additions & 1 deletion lib/camping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ def M;def M;end;constants.map{|c|k=const_get(c)
def method_missing m,c,*a;X.M;h=Hash===a[-1]?a.pop: {}
e=H[Rack::MockRequest.env_for('',h[:env]||{})]
k=X.const_get(c).new(e,m.to_s);k.send("input=",h[:input])if h[:input]
k.service(*a);end;end;module Views;include X,Helpers end;module Models
k.service(*a);end;def use*a;m=a.shift.new(method(:call),*a);meta_def(:call){|e|
m.call(e)}end end;module Views;include X,Helpers end;module Models
autoload:Base,'camping/ar';def Y;self;end end;autoload:Mab,'camping/mab';C end

0 comments on commit 0d21c24

Please sign in to comment.