Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first try

  • Loading branch information...
commit 2f541b041644165f87edf1350e56d387fb64933f 1 parent 3351335
@ddollar authored
Showing with 38 additions and 1 deletion.
  1. +1 −1  Rakefile
  2. +37 −0 lib/rack/maintenance.rb
View
2  Rakefile
@@ -12,7 +12,7 @@ begin
gem.authors = ["David Dollar"]
gem.add_development_dependency "rspec"
gem.add_development_dependency "yard"
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
+ gem.add_dependency 'rake', '>= 1.0'
end
Jeweler::GemcutterTasks.new
rescue LoadError
View
37 lib/rack/maintenance.rb
@@ -0,0 +1,37 @@
+require 'rack'
+
+class Rack::Maintenance
+
+ attr_reader :app, :options
+
+ def initialize(app, options={})
+ @app = app
+ @options = options
+
+ raise(ArgumentError, 'Must specify a :file') unless options[:file]
+ end
+
+ def call(env)
+ if maintenance?
+ data = File.read(file)
+ [ 503, { 'Content-Type' => 'text/html', 'Content-Length' => data.length }, [data] ]
+ else
+ app.call(env)
+ end
+ end
+
+private ######################################################################
+
+ def environment
+ options[:env]
+ end
+
+ def file
+ options[:file]
+ end
+
+ def maintenance?
+ environment ? ENV[environment] : File.exists?(file)
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.