Permalink
Browse files

Meh. Obviously we can't cache variables that need to be redefined eve…

…ry single request.
  • Loading branch information...
1 parent 60d4160 commit 8b60bd625f8223c6e64ca5689785a387465b06b7 @fnando committed Mar 13, 2012
Showing with 40 additions and 16 deletions.
  1. +29 −0 Gemfile.lock
  2. +11 −16 fu.rb
View
29 Gemfile.lock
@@ -0,0 +1,29 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ activesupport (3.2.2)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ daemons (1.1.8)
+ eventmachine (0.12.10)
+ i18n (0.6.0)
+ multi_json (1.1.0)
+ rack (1.4.1)
+ rack-contrib (1.1.0)
+ rack (>= 0.9.1)
+ rack-mount (0.8.3)
+ rack (>= 1.0.0)
+ thin (1.3.1)
+ daemons (>= 1.0.9)
+ eventmachine (>= 0.12.6)
+ rack (>= 1.0.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activesupport
+ rack
+ rack-contrib
+ rack-mount
+ thin
View
27 fu.rb
@@ -5,28 +5,23 @@
class FU
class App
- attr_reader :env
+ attr_reader :env, :params, :request
attr_accessor :callback
def initialize(callback)
@callback = callback
end
- def request
- @request ||= Rack::Request.new(env)
- end
-
- def params
- @params ||= begin
+ def call(env)
+ @env = env
+ @request = Rack::Request.new(env)
+ @params = begin
params = request.params || {}
params.merge!(request.env["rack.request.form_hash"] || {})
params.merge!(request.env["rack.routing_args"] || {})
ActiveSupport::HashWithIndifferentAccess.new(params)
end
- end
- def call(env)
- @env = env
instance_eval(&callback)
end
end
@@ -104,21 +99,21 @@ def compile_path(path)
app = FU.app do
use Rack::Runtime
- get "/" do
- name = params.fetch(:name, "Rackers")
-
+ get "/:name" do
[
200,
{"Content-Type" => "text/html"},
- ["Hello #{name}!"]
+ ["Hello #{params[:name]}!"]
]
end
- get "/:name" do
+ get "/" do
+ name = params.fetch(:name, "Rackers")
+
[
200,
{"Content-Type" => "text/html"},
- ["Hello #{params[:name]}!"]
+ ["Hello #{name}!"]
]
end

0 comments on commit 8b60bd6

Please sign in to comment.