Class: Rack::Staging
- Inherits:
-
Auth::Basic
- Object
- Auth::Basic
- Rack::Staging
- Defined in:
- lib/rack_staging.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, detect_proc = nil) ⇒ Staging
constructor
A new instance of Staging.
- #robots_txt ⇒ Object
- #robots_txt?(env) ⇒ Boolean
Constructor Details
#initialize(app, detect_proc = nil) ⇒ Staging
Returns a new instance of Staging.
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/rack_staging.rb', line 4 def initialize(app, detect_proc = nil) @app = app @staging_detect = detect_proc || lambda do |env| env["HTTP_HOST"] =~ /staging/ || ENV["STAGING"] end super app, 'staging' do |username, password| [username, password] == [ENV["STAGING_USER"], ENV["STAGING_PASS"]] end end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/rack_staging.rb', line 16 def call(env) @env = env if @staging_detect.call(@env) return robots_txt if robots_txt?(env) super else @app.call(env) end end |
#robots_txt ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/rack_staging.rb', line 30 def robots_txt body = <<-EOF User-agent: * Disallow: / EOF [ 200, {'Content-Type' => 'text/plain'}, [body] ] end |
#robots_txt?(env) ⇒ Boolean
26 27 28 |
# File 'lib/rack_staging.rb', line 26 def robots_txt?(env) env["PATH_INFO"] == "/robots.txt" end |