turnout 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: adf33ca2dc98cb6fa15b8e17290193dd24f16795
4
+ data.tar.gz: abff4e95ca98a1dc8bc2d10e11eea6e677fb0724
5
+ SHA512:
6
+ metadata.gz: 9d3f40a2d6701f652ffbddf93cb07f7b2d7ca7ce229b29283ad0079b51b1fbf948fdb597bfd36bd5000746b3dd1d74e3ffc48687c58c0a897f3b5e113ee3e164
7
+ data.tar.gz: eca42d7c3acb642cc8dc5aa68f5790838756279a74eb143268087172ec1d69c89f4e82486f3c3fdfef8afea462454be53a11d8acbf0cea198a51fadfb698c432
@@ -1,4 +1,4 @@
1
- Turnout
1
+ Turnout [![Build Status](https://travis-ci.org/biola/turnout.png?branch=master)](https://travis-ci.org/biola/turnout)
2
2
  =======
3
3
  Turnout is a [Ruby on Rails](http://rubyonrails.org) engine with a [Rack](http://rack.rubyforge.org/) component that allows you to put your Rails app in maintenance mode.
4
4
 
@@ -11,6 +11,7 @@ Features
11
11
  * Allow certain paths to be accessible during maintenance
12
12
  * Easily override the default maintenance.html file with your own
13
13
  * Simple [YAML](http://yaml.org) based config file for easy activation, deactivation and configuration without the rake commands
14
+ * Supports Rails 2.3 - 3.0 and Ruby 1.8.7 - 1.9.3
14
15
 
15
16
  Installation
16
17
  ============
@@ -23,7 +24,7 @@ In your `Gemfile` add:
23
24
  then run
24
25
 
25
26
  bundle install
26
-
27
+
27
28
  Rails 2.3
28
29
  ---------
29
30
  In your `config/environment.rb` file add:
@@ -37,7 +38,7 @@ then run
37
38
  then in your `Rakefile` add:
38
39
 
39
40
  require 'turnout/rake_tasks'
40
-
41
+
41
42
 
42
43
  Activation
43
44
  ==========
@@ -47,7 +48,7 @@ Activation
47
48
  or
48
49
 
49
50
  rake maintenance:start reason="Somebody googled Google!"
50
-
51
+
51
52
  or
52
53
 
53
54
  rake maintenance:start allowed_paths="/login,^/faqs/[0-9]*"
@@ -78,6 +79,15 @@ Customization
78
79
 
79
80
  A [default maintenance page](https://github.com/biola/turnout/blob/master/public/maintenance.html) is provided, but you can create your own `public/maintenance.html` instead. If you provide a `reason` to the rake task, Turnout will use [Nokogiri](http://nokogiri.org) to parse the `maintenance.html` file and attempt to find a tag with `id="reason"`. It will replace the `inner_html` of the tag with the reason you provided. So be sure your `maintenance.html` file can be parsed as HTML.
80
81
 
82
+ Tips
83
+ ====
84
+
85
+ There is no `denied_paths` feature because turnout denies everyhing by default.
86
+ However you can achieve the same sort of functionality by using
87
+ [negative lookaheads](http://www.regular-expressions.info/lookaround.html) with the `allowed_paths` setting, like so:
88
+
89
+ rake maintenance:start allowed_paths="^(?!/your/under/maintenance/path)"
90
+
81
91
  Behind the Scenes
82
92
  =================
83
93
  On every request the Rack app will check to see if `tmp/maintenance.yml` exists. If the file exists the maintenance page will be shown (unless allowed IPs are given and the requester is in the allowed range).
@@ -96,4 +106,4 @@ Example maintenance.yml File
96
106
  - ^/contact_us
97
107
  allowed_ips:
98
108
  - 127.0.0.1
99
- - 192.168.0.0/24
109
+ - 192.168.0.0/24
@@ -4,7 +4,6 @@ require 'ipaddr'
4
4
  require 'nokogiri'
5
5
 
6
6
  class Rack::Turnout
7
-
8
7
  def initialize(app, config={})
9
8
  @app = app
10
9
  @config = config
@@ -12,7 +11,7 @@ class Rack::Turnout
12
11
 
13
12
  def call(env)
14
13
  reload_settings
15
-
14
+
16
15
  if on?(env)
17
16
  [ 503, { 'Content-Type' => 'text/html', 'Content-Length' => content_length }, [content] ]
18
17
  else
@@ -21,13 +20,13 @@ class Rack::Turnout
21
20
  end
22
21
 
23
22
  protected
24
-
23
+
25
24
  def on?(env)
26
25
  request = Rack::Request.new(env)
27
-
26
+
28
27
  return false if path_allowed?(request.path)
29
28
  return false if ip_allowed?(request.ip)
30
- File.exists? settings_file
29
+ maintenance_file_exists?
31
30
  end
32
31
 
33
32
  def path_allowed?(path)
@@ -68,6 +67,10 @@ class Rack::Turnout
68
67
  app_root.join('tmp', 'maintenance.yml')
69
68
  end
70
69
 
70
+ def maintenance_file_exists?
71
+ File.exists? settings_file
72
+ end
73
+
71
74
  def maintenance_page
72
75
  File.exists?(app_maintenance_page) ? app_maintenance_page : default_maintenance_page
73
76
  end
@@ -86,14 +89,13 @@ class Rack::Turnout
86
89
 
87
90
  def content
88
91
  content = File.open(maintenance_page, 'rb').read
89
-
92
+
90
93
  if settings['reason']
91
94
  html = Nokogiri::HTML(content)
92
- html.at_css('#reason').inner_html = settings['reason']
95
+ html.at_css('#reason').inner_html = Nokogiri::HTML.fragment(settings['reason'])
93
96
  content = html.to_s
94
97
  end
95
-
98
+
96
99
  content
97
100
  end
98
-
99
- end
101
+ end
@@ -1,5 +1,4 @@
1
1
  namespace :maintenance do
2
-
3
2
  desc 'Enable the maintenance mode page ("reason", "allowed_paths" and "allowed_ips" can be passed as environment variables)'
4
3
  task :start do |t, args|
5
4
  settings = {
@@ -7,22 +6,22 @@ namespace :maintenance do
7
6
  'allowed_paths' => split_paths(ENV['allowed_paths']),
8
7
  'allowed_ips' => split_ips(ENV['allowed_ips'])
9
8
  }
10
-
9
+
11
10
  file = File.open settings_file, 'w'
12
11
  file.write settings.to_yaml
13
12
  file.close
14
-
13
+
15
14
  puts "Created #{settings_file}"
16
15
  puts "Run `rake maintenance:end` to stop maintenance mode"
17
16
  end
18
17
 
19
18
  desc 'Disable the maintenance mode page'
20
- task :end do
19
+ task :end do
21
20
  File.delete settings_file
22
-
21
+
23
22
  puts "Deleted #{settings_file}"
24
23
  end
25
-
24
+
26
25
  def settings_file
27
26
  Rails.root.join('tmp', 'maintenance.yml')
28
27
  end
@@ -42,5 +41,4 @@ namespace :maintenance do
42
41
  def split_ips(ips_string)
43
42
  ips_string.to_s.split(',')
44
43
  end
45
-
46
- end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module Turnout
2
- require 'turnout/engine'
2
+ require 'turnout/engine' if defined? Rails
3
3
  end
@@ -1,12 +1,9 @@
1
1
  require 'turnout'
2
2
  require 'rack/turnout'
3
- require 'rails' unless defined? Rails
3
+ require 'rails'
4
4
 
5
5
  # For Rails 3
6
6
  if defined? Rails::Engine
7
-
8
- require 'active_record'
9
-
10
7
  module Turnout
11
8
  class Engine < Rails::Engine
12
9
  initializer 'turnout.add_to_middleware_stack' do |app|
@@ -14,5 +11,4 @@ if defined? Rails::Engine
14
11
  end
15
12
  end
16
13
  end
17
-
18
- end
14
+ end
@@ -1,5 +1,3 @@
1
1
  module Turnout
2
-
3
- VERSION = '0.2.2'
4
-
2
+ VERSION = '0.2.3'
5
3
  end
@@ -1,19 +1,20 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
+ <meta charset="UTF-8">
4
5
  <title>Down for Maintenance</title>
5
6
 
6
7
  <style type="text/css">
7
-
8
+
8
9
  *{
9
10
  font-family: Arial, Helvetica, sans-serif;
10
11
  }
11
-
12
+
12
13
  body{
13
14
  margin: 0;
14
15
  background-color: #fff;
15
16
  }
16
-
17
+
17
18
  #page{
18
19
  position: relative;
19
20
  width: 550px;
@@ -27,43 +28,43 @@
27
28
  -webkit-box-shadow: inset 0 2px 10px #ccc;
28
29
  box-shadow: inset 0 2px 10px #ccc;
29
30
  }
30
-
31
+
31
32
  header, #body{
32
33
  width: 400px;
33
34
  margin: 0 auto;
34
35
  }
35
-
36
+
36
37
  h1{
37
38
  margin: 0;
38
39
  color: #CC3601;
39
40
  font-size: 26pt;
40
41
  border-bottom: solid 4px #666;
41
42
  }
42
-
43
+
43
44
  #reason{
44
45
  margin: 10px 0;
45
46
  color: #333;
46
47
  }
47
-
48
+
48
49
  </style>
49
50
 
50
51
  </head>
51
52
  <body>
52
-
53
+
53
54
  <section id="page">
54
-
55
+
55
56
  <header>
56
57
  <h1>Down for Maintenance</h1>
57
58
  </header>
58
-
59
+
59
60
  <section id="body">
60
61
  <div id="reason">
61
62
  <p>The site is temporarily down for maintenance.</p>
62
63
  <p>Please check back soon.</p>
63
64
  </div>
64
65
  </section>
65
-
66
+
66
67
  </section>
67
-
68
+
68
69
  </body>
69
- </html>
70
+ </html>
metadata CHANGED
@@ -1,28 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turnout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
5
- prerelease:
4
+ version: 0.2.3
6
5
  platform: ruby
7
6
  authors:
8
7
  - Adam Crownoble
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-07-29 00:00:00.000000000 -07:00
13
- default_executable:
11
+ date: 2013-05-17 00:00:00.000000000 Z
14
12
  dependencies:
15
13
  - !ruby/object:Gem::Dependency
16
14
  name: nokogiri
17
- requirement: &72111600 !ruby/object:Gem::Requirement
18
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
19
16
  requirements:
20
17
  - - ~>
21
18
  - !ruby/object:Gem::Version
22
19
  version: '1.3'
23
20
  type: :runtime
24
21
  prerelease: false
25
- version_requirements: *72111600
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.12'
26
69
  description: Turnout makes it easy to put your Rails application into maintenance
27
70
  mode
28
71
  email: adam.crownoble@biola.edu
@@ -36,33 +79,31 @@ files:
36
79
  - lib/turnout.rb
37
80
  - lib/rack/turnout.rb
38
81
  - lib/turnout/version.rb
39
- - lib/turnout/rake_tasks.rb
40
82
  - lib/turnout/engine.rb
83
+ - lib/turnout/rake_tasks.rb
41
84
  - lib/tasks/maintenance.rake
42
85
  - public/maintenance.html
43
- has_rdoc: true
44
86
  homepage: https://github.com/biola/turnout
45
87
  licenses: []
88
+ metadata: {}
46
89
  post_install_message:
47
90
  rdoc_options: []
48
91
  require_paths:
49
92
  - lib
50
93
  required_ruby_version: !ruby/object:Gem::Requirement
51
- none: false
52
94
  requirements:
53
- - - ! '>='
95
+ - - '>='
54
96
  - !ruby/object:Gem::Version
55
97
  version: '0'
56
98
  required_rubygems_version: !ruby/object:Gem::Requirement
57
- none: false
58
99
  requirements:
59
- - - ! '>='
100
+ - - '>='
60
101
  - !ruby/object:Gem::Version
61
102
  version: '0'
62
103
  requirements: []
63
104
  rubyforge_project:
64
- rubygems_version: 1.6.2
105
+ rubygems_version: 2.0.0.rc.2
65
106
  signing_key:
66
- specification_version: 3
107
+ specification_version: 4
67
108
  summary: A Rack based maintenance mode plugin for Rails
68
109
  test_files: []