Permalink
Browse files

Cleanup.

  • Loading branch information...
1 parent cbcf57c commit b866434452025d81ceab4aa228af7337b7bcda0f @DouweM DouweM committed Sep 6, 2013
Showing with 5 additions and 16 deletions.
  1. +3 −4 lib/http_accept_language/middleware.rb
  2. +1 −6 lib/http_accept_language/railtie.rb
  3. +1 −6 spec/middleware_spec.rb
@@ -1,17 +1,16 @@
module HttpAcceptLanguage
class Middleware
-
def initialize(app)
@app = app
end
def call(env)
- env["http_accept_language"] = Parser.new(env['HTTP_ACCEPT_LANGUAGE'])
+ env["http_accept_language.parser"] = Parser.new(env["HTTP_ACCEPT_LANGUAGE"])
def env.http_accept_language
- self["http_accept_language"]
+ self["http_accept_language.parser"]
end
+
@app.call(env)
end
-
end
end
@@ -1,22 +1,17 @@
module HttpAcceptLanguage
class Railtie < ::Rails::Railtie
-
initializer "http_accept_language.add_middleware" do |app|
app.middleware.use Middleware
ActiveSupport.on_load :action_controller do
include EasyAccess
end
end
-
end
module EasyAccess
-
def http_accept_language
- @http_accept_language ||= env.respond_to?(:http_accept_language) ? env.http_accept_language : Parser.new("")
+ @http_accept_language ||= request.env["http_accept_language.parser"] || Parser.new("")
end
-
end
-
end
View
@@ -18,11 +18,6 @@ def call(env)
end
-class NoOpApp
- def call(env)
- end
-end
-
describe "Rack integration" do
include Rack::Test::Methods
@@ -35,7 +30,7 @@ def app
it "handles reuse of the env instance" do
env = { "HTTP_ACCEPT_LANGUAGE" => "en" }
- app = NoOpApp.new
+ app = lambda { |env| env }
middleware = HttpAcceptLanguage::Middleware.new(app)
middleware.call(env)
env.http_accept_language.user_preferred_languages.should eq %w{en}

0 comments on commit b866434

Please sign in to comment.