rack-maintenance 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1390fad941b259bf2086c2c01f5d87a1049a3467
4
+ data.tar.gz: 638d2bf82a4dc208b6d9c5332b891e94b8be248f
5
+ SHA512:
6
+ metadata.gz: b271c2aed6ffe16ad48f7348e0703bf3f25d402895cc4f9d80c0e6fd6f1c663e80bb8d40adc83029f63ff41837d392f53df47f24f61f43ae4d7234bba5ccccfb
7
+ data.tar.gz: 0a0f2aefdbc3fc51ccd762ee94f66037203c6714d16612e27355b3a58d149b3689eefe51aa870bcff6f5b331a30f669b9cddc29ca7ecf5f307439089544c15ce
@@ -1,7 +1,7 @@
1
1
  = rack-maintenance
2
2
 
3
3
  Rack::Maintenance is a simple Rack middleware to detect the existence of a
4
- maintenance.html page and display that instead of incoming requests.
4
+ maintenance page and display that instead of incoming requests.
5
5
 
6
6
  {<img src="https://secure.travis-ci.org/tilsammans/rack-maintenance.png" />}[http://travis-ci.org/tilsammans/rack-maintenance]
7
7
 
@@ -19,11 +19,17 @@ and then run `bundle`.
19
19
 
20
20
  == Usage
21
21
 
22
- # config/environment.rb
22
+ # html maintenance response
23
23
  config.middleware.use 'Rack::Maintenance',
24
24
  :file => Rails.root.join('public', 'maintenance.html'),
25
25
  :env => 'MAINTENANCE'
26
26
 
27
+ # json maintenance response
28
+ # it's up to you to provide a valid JSON file!
29
+ config.middleware.use 'Rack::Maintenance',
30
+ :file => Rails.root.join('public', 'maintenance.json'),
31
+ :env => 'MAINTENANCE'
32
+
27
33
  If <tt>:env</tt> is specified, all requests will be shown the
28
34
  maintenance page if the environment variable is set.
29
35
 
@@ -32,12 +38,12 @@ If <tt>:env</tt> is not specified, the maintenance page will be shown if it exis
32
38
  == Note on Patches/Pull Requests
33
39
 
34
40
  * Fork the project.
35
- * Make your feature addition or bug fix.
36
- * Add tests for it. This is important so I don't break it in a
37
- future version unintentionally.
41
+ * Make your feature addition or bug fix in a branch.
42
+ * Add tests for it.
38
43
  * Commit, do not mess with Rakefile or VERSION (do that in a separate commit if you want a local version)
39
- * Send me a pull request. Bonus points for topic branches.
44
+ * Push your branch.
45
+ * Send me a pull request.
40
46
 
41
- == Copyright
47
+ == License
42
48
 
43
- Copyright (c) 2009 David Dollar. See LICENSE for details.
49
+ BSD. See LICENSE for details.
@@ -14,7 +14,7 @@ class Rack::Maintenance
14
14
  def call(env)
15
15
  if maintenance? && path_in_app(env)
16
16
  data = File.read(file)
17
- [ 503, { 'Content-Type' => 'text/html', 'Content-Length' => data.length.to_s }, [data] ]
17
+ [ 503, { 'Content-Type' => content_type, 'Content-Length' => data.length.to_s }, [data] ]
18
18
  else
19
19
  app.call(env)
20
20
  end
@@ -22,6 +22,10 @@ class Rack::Maintenance
22
22
 
23
23
  private ######################################################################
24
24
 
25
+ def content_type
26
+ file.end_with?('json') ? 'application/json' : 'text/html'
27
+ end
28
+
25
29
  def environment
26
30
  options[:env]
27
31
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Maintenance
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -1,9 +1,9 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
  require 'fileutils'
3
3
 
4
- describe "RackMaintenance" do
4
+ shared_examples "RackMaintenance" do
5
5
  let(:app) { Class.new { def call(env); end }.new }
6
- let(:rack) { Rack::Maintenance.new(app, :file => "spec/maintenance.html") }
6
+ let(:rack) { Rack::Maintenance.new(app, :file => file_name) }
7
7
 
8
8
  context "without a :file option" do
9
9
  it "raises an error" do
@@ -22,11 +22,11 @@ describe "RackMaintenance" do
22
22
 
23
23
  context "with maintenance file" do
24
24
  before do
25
- FileUtils.touch 'spec/maintenance.html'
25
+ FileUtils.touch file_name
26
26
  end
27
27
 
28
28
  after do
29
- FileUtils.rm 'spec/maintenance.html'
29
+ FileUtils.rm file_name
30
30
  end
31
31
 
32
32
  it "does not call the app" do
@@ -35,11 +35,11 @@ describe "RackMaintenance" do
35
35
  end
36
36
 
37
37
  it "returns the maintenance response" do
38
- rack.call({}).should eq [503, {"Content-Type"=>"text/html", "Content-Length"=>"0"}, [""]]
38
+ rack.call({}).should eq [503, {"Content-Type"=>content_type, "Content-Length"=>"0"}, [""]]
39
39
  end
40
40
 
41
41
  context "and :env option MAINTENANCE" do
42
- let(:rack) { Rack::Maintenance.new(app, :file => "spec/maintenance.html", :env => "MAINTENANCE") }
42
+ let(:rack) { Rack::Maintenance.new(app, :file => file_name, :env => "MAINTENANCE") }
43
43
 
44
44
  context "outside MAINTENANCE env" do
45
45
  it "calls the app" do
@@ -53,6 +53,10 @@ describe "RackMaintenance" do
53
53
  ENV['MAINTENANCE'] = "true"
54
54
  end
55
55
 
56
+ after do
57
+ ENV.delete("MAINTENANCE")
58
+ end
59
+
56
60
  it "does not call the app" do
57
61
  app.should_not_receive :call
58
62
  rack.call({})
@@ -68,3 +72,18 @@ describe "RackMaintenance" do
68
72
  end
69
73
  end
70
74
  end
75
+
76
+ describe "RackMaintenance with json maintenance file" do
77
+ it_behaves_like "RackMaintenance" do
78
+ let(:file_name) { "spec/maintenance.json" }
79
+ let(:content_type) { "application/json" }
80
+ end
81
+ end
82
+
83
+ describe "RackMaintenance with html maintenance file" do
84
+ it_behaves_like "RackMaintenance" do
85
+ let(:file_name) { "spec/maintenance.html" }
86
+ let(:content_type) { "text/html" }
87
+ end
88
+ end
89
+
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-maintenance
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
5
- prerelease:
4
+ version: 1.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - David Dollar
@@ -10,38 +9,34 @@ authors:
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-09-28 00:00:00.000000000 Z
12
+ date: 2014-02-13 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rack
17
16
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
17
  requirements:
20
- - - ! '>='
18
+ - - '>='
21
19
  - !ruby/object:Gem::Version
22
20
  version: '1.0'
23
21
  type: :runtime
24
22
  prerelease: false
25
23
  version_requirements: !ruby/object:Gem::Requirement
26
- none: false
27
24
  requirements:
28
- - - ! '>='
25
+ - - '>='
29
26
  - !ruby/object:Gem::Version
30
27
  version: '1.0'
31
28
  - !ruby/object:Gem::Dependency
32
29
  name: rspec
33
30
  requirement: !ruby/object:Gem::Requirement
34
- none: false
35
31
  requirements:
36
- - - ! '>='
32
+ - - '>='
37
33
  - !ruby/object:Gem::Version
38
34
  version: '2.0'
39
35
  type: :development
40
36
  prerelease: false
41
37
  version_requirements: !ruby/object:Gem::Requirement
42
- none: false
43
38
  requirements:
44
- - - ! '>='
39
+ - - '>='
45
40
  - !ruby/object:Gem::Version
46
41
  version: '2.0'
47
42
  description: Detect and show a maintenance page
@@ -62,29 +57,27 @@ files:
62
57
  - spec/spec_helper.rb
63
58
  homepage: http://github.com/tilsammans/rack-maintenance
64
59
  licenses: []
60
+ metadata: {}
65
61
  post_install_message:
66
62
  rdoc_options: []
67
63
  require_paths:
68
64
  - lib
69
65
  required_ruby_version: !ruby/object:Gem::Requirement
70
- none: false
71
66
  requirements:
72
- - - ! '>='
67
+ - - '>='
73
68
  - !ruby/object:Gem::Version
74
69
  version: '0'
75
70
  required_rubygems_version: !ruby/object:Gem::Requirement
76
- none: false
77
71
  requirements:
78
- - - ! '>='
72
+ - - '>='
79
73
  - !ruby/object:Gem::Version
80
74
  version: '0'
81
75
  requirements: []
82
76
  rubyforge_project:
83
- rubygems_version: 1.8.23
77
+ rubygems_version: 2.0.14
84
78
  signing_key:
85
- specification_version: 3
79
+ specification_version: 4
86
80
  summary: Detect and show a maintenance page
87
81
  test_files:
88
82
  - spec/rack-maintenance_spec.rb
89
83
  - spec/spec_helper.rb
90
- has_rdoc: