rack-alive 0.0.1

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,9 @@
1
+ .DS_Store
2
+ .bundle
3
+ .rbx
4
+ .*~
5
+ Gemfile.lock
6
+ pkg/*
7
+ *.gem
8
+ *.rbc
9
+ *~
@@ -0,0 +1,10 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - ree
5
+ - ruby-head
6
+ - rbx
7
+ - rbx-2.0
8
+ - jruby
9
+ notifications:
10
+ disabled: true
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rack-alive.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ group :darwin do
8
+ gem 'rb-fsevent'
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ guard 'bundler' do
2
+ watch('Gemfile')
3
+ watch(/^.+\.gemspec/)
4
+ end
5
+
6
+ guard 'minitest' do
7
+ watch(%r|^spec/(.*)_spec\.rb|)
8
+ watch(%r|^lib/(.*)\.rb|) # { |m| "spec/#{m[1]}_spec.rb" }
9
+ watch(%r|^spec/spec_helper\.rb|) { "spec" }
10
+ end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Jonas Grimfelt, Merchii. http://merchii.com
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,60 @@
1
+ h1. RACK-ALIVE "!https://secure.travis-ci.org/merchii/rack-alive.png!":http://travis-ci.org/merchii/rack-alive
2
+
3
+ _Rack middleware for checking if app is alive or not - optionally via custom condition(s)._
4
+
5
+ h2. Installation
6
+
7
+ Add to your @Gemfile@:
8
+
9
+ <pre>
10
+ gem 'rack-alive'
11
+ </pre>
12
+
13
+ ...and @bundle install@.
14
+
15
+ h2. Usage
16
+
17
+ *Minimal:*
18
+
19
+ <pre>
20
+ require 'rack/alive'
21
+
22
+ use Rack::Alive
23
+ </pre>
24
+
25
+ *Advanced:*
26
+
27
+ <pre>
28
+ require 'rack/alive'
29
+
30
+ use Rack::Alive, proc {
31
+ # Test DB-connection.
32
+ db_alive =
33
+ begin
34
+ ActiveRecord::Base.connection.select_all('select 1')
35
+ true
36
+ rescue
37
+ false
38
+ end
39
+
40
+ # Check that you got all horses/unicorns in the stable...or something.
41
+ got_all_horses = ENV['HORSES_IN_THE_STABLE'].to_i == 5
42
+
43
+ db_alive && got_all_horses
44
+ }
45
+ </pre>
46
+
47
+ h2. Test
48
+
49
+ <pre>
50
+ GET /alive?
51
+ </pre>
52
+
53
+ h2. Notes
54
+
55
+ This gem was developed for our own requirements at *"Merchii":http://github.com/merchii*, so feel free to send pull-requests with enhancements of any kind (features, bug-fixes, documentation, tests, etc.) to make it better or useful for you as well.
56
+
57
+ h2. License
58
+
59
+ Released under the MIT license.
60
+ Copyright (c) "Jonas Grimfelt":http://github.com/grimen, "Merchii":http://github.com/merchii
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ task :default => :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << ['lib', 'spec']
8
+ t.pattern = "spec/*_spec.rb"
9
+ end
data/TODO ADDED
@@ -0,0 +1,12 @@
1
+ == TODO
2
+
3
+ -- MAYBE ...
4
+
5
+ - [feature]: Support different response-formats (with more detailed status data):
6
+
7
+ Example: JSON
8
+
9
+ {
10
+ status: 500,
11
+ message: "This is so FAIL..."
12
+ }
@@ -0,0 +1,36 @@
1
+ require "rack/alive/version"
2
+
3
+ module Rack
4
+ class Alive
5
+
6
+ def initialize(app, conditional_block = nil)
7
+ @app, @path, @conditional_block = app, "/alive", conditional_block
8
+ end
9
+
10
+ def call(env)
11
+ if @path == env['PATH_INFO']
12
+ alive?(env)
13
+ else
14
+ @app.call(env)
15
+ end
16
+ end
17
+
18
+ protected
19
+
20
+ def alive_response(sucess)
21
+ if sucess
22
+ [200, {'Content-Type' => 'text/plain'}, "true"]
23
+ else
24
+ [500, {'Content-Type' => 'text/plain'}, "false"]
25
+ end
26
+ end
27
+
28
+ def alive?(env)
29
+ is_alive = @conditional_block.respond_to?(:call) ? @conditional_block.call(env) : true
30
+ alive_response(is_alive)
31
+ rescue
32
+ alive_response(false)
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class Alive
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rack/alive/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rack-alive"
7
+ s.version = Rack::Alive::VERSION
8
+ s.authors = ["Merchii", "Jonas Grimfelt"]
9
+ s.email = ["jonas@merchii.com", "grimen@gmail.com"]
10
+ s.homepage = "http://github.com/merchii/rack-alive"
11
+ s.summary = %q{Rack middleware for checking if app is alive or not - optionally via custom condition(s).}
12
+ s.description = s.summary
13
+
14
+ s.rubyforge_project = s.name
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- spec/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_runtime_dependency 'rack'
22
+
23
+ s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'bundler'
25
+ s.add_development_dependency 'minitest'
26
+ s.add_development_dependency 'guard'
27
+ s.add_development_dependency 'guard-bundler'
28
+ s.add_development_dependency 'guard-minitest'
29
+ s.add_development_dependency 'rack-test'
30
+ end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rack::Alive do
4
+
5
+ describe "VERSION" do
6
+ it 'should be defined' do
7
+ defined?(::Rack::Alive::VERSION)
8
+ end
9
+
10
+ it 'should be a valid version string (e.g. "0.0.1", or "0.0.1.rc1")' do
11
+ valid_version_string = /^\d+\.\d+\.\d+/
12
+ Rack::Alive::VERSION.must_match valid_version_string
13
+ end
14
+ end
15
+
16
+ describe "Middleware" do
17
+ before do
18
+ @app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, ""] }
19
+ end
20
+
21
+ describe "Minimal setup: No custom conditions" do
22
+ it 'should be alive' do
23
+ request = Rack::MockRequest.env_for("/alive?")
24
+ response = Rack::Alive.new(@app).call(request)
25
+ status(response).must_equal 200
26
+ body(response).must_equal "true"
27
+ end
28
+ end
29
+
30
+ describe "Advanced setup: Using custom alive? conditions" do
31
+ it 'should not be alive if block conditions are false' do
32
+ request = Rack::MockRequest.env_for("/alive?")
33
+ response = Rack::Alive.new(@app, proc {
34
+ false
35
+ }).call(request)
36
+ status(response).must_equal 500
37
+ body(response).must_equal "false"
38
+ end
39
+
40
+ it 'should not be alive if block conditions raise error' do
41
+ request = Rack::MockRequest.env_for("/alive?")
42
+ response = Rack::Alive.new(@app, proc {
43
+ raise "SHIT - WHERE ARE ALL THE HORSES???!!! *drama-queen scream*"
44
+ }).call(request)
45
+ status(response).must_equal 500
46
+ body(response).must_equal "false"
47
+ end
48
+
49
+ it 'should be alive if block conditions are true' do
50
+ request = Rack::MockRequest.env_for("/alive?")
51
+ response = Rack::Alive.new(@app, proc {
52
+ true
53
+ }).call(request)
54
+ status(response).must_equal 200
55
+ body(response).must_equal "true"
56
+ end
57
+ end
58
+ end
59
+
60
+ private
61
+
62
+ def status(response)
63
+ response[0]
64
+ end
65
+
66
+ def headers(response)
67
+ response[1]
68
+ end
69
+
70
+ def body(response)
71
+ response[2]
72
+ end
73
+
74
+ end
@@ -0,0 +1,9 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'minitest/unit'
4
+ require 'minitest/spec'
5
+ require 'minitest/pride'
6
+
7
+ require 'rack/mock'
8
+
9
+ require 'rack/alive'
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-alive
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Merchii
9
+ - Jonas Grimfelt
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2011-09-19 00:00:00 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rack
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: bundler
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :development
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: minitest
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: guard
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: guard-bundler
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: guard-minitest
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: rack-test
95
+ requirement: &id008 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: "0"
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *id008
104
+ description: Rack middleware for checking if app is alive or not - optionally via custom condition(s).
105
+ email:
106
+ - jonas@merchii.com
107
+ - grimen@gmail.com
108
+ executables: []
109
+
110
+ extensions: []
111
+
112
+ extra_rdoc_files: []
113
+
114
+ files:
115
+ - .gitignore
116
+ - .travis.yml
117
+ - Gemfile
118
+ - Guardfile
119
+ - MIT-LICENSE
120
+ - README.textile
121
+ - Rakefile
122
+ - TODO
123
+ - lib/rack/alive.rb
124
+ - lib/rack/alive/version.rb
125
+ - rack-alive.gemspec
126
+ - spec/rack-alive_spec.rb
127
+ - spec/spec_helper.rb
128
+ homepage: http://github.com/merchii/rack-alive
129
+ licenses: []
130
+
131
+ post_install_message:
132
+ rdoc_options: []
133
+
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ hash: 2161060546122644534
142
+ segments:
143
+ - 0
144
+ version: "0"
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ hash: 2161060546122644534
151
+ segments:
152
+ - 0
153
+ version: "0"
154
+ requirements: []
155
+
156
+ rubyforge_project: rack-alive
157
+ rubygems_version: 1.8.10
158
+ signing_key:
159
+ specification_version: 3
160
+ summary: Rack middleware for checking if app is alive or not - optionally via custom condition(s).
161
+ test_files:
162
+ - spec/rack-alive_spec.rb
163
+ - spec/spec_helper.rb