Skip to content

Commit

Permalink
Meh. Obviously we can't cache variables that need to be redefined eve…
Browse files Browse the repository at this point in the history
…ry single request.
  • Loading branch information
fnando committed Mar 13, 2012
1 parent 60d4160 commit 8b60bd6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
29 changes: 29 additions & 0 deletions 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
27 changes: 11 additions & 16 deletions fu.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 8b60bd6

Please sign in to comment.