rack-heroku_env 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rack-heroku-env.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Junya Ogura
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.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ rack-heroku_env
2
+ ====
3
+
4
+ A gem that provides exposing Heroku environment variables as HTTP response headers as rack middleware.
5
+
6
+ ![Screenshot](http://farm7.static.flickr.com/6072/6034883614_f94d8d6d61_b.jpg)
7
+
8
+ `Rack::HerokuEnv` exposes these variables:
9
+
10
+ * `HTTP_X_HEROKU_DYNOS_IN_USE` as `X-Heroku-Dynos-In-Use`
11
+ * `HTTP_X_HEROKU_QUEUE_DEPTH` as `X-Heroku-Queue-Depth`
12
+ * `HTTP_X_HEROKU_QUEUE_WAIT_TIME` as `X-Heroku-Queue-Wait-Time`
13
+
14
+
15
+ Usage
16
+ ----
17
+
18
+ ### Rails 3
19
+
20
+ # Gemfile
21
+ gem 'rack-heroku_env', :require => 'rack/heroku_env'
22
+
23
+ # config/application.rb
24
+ config.middleware.use Rack::HerokuEnv
25
+
26
+
27
+ ### Sinatra
28
+
29
+ require 'rack/heroku_env'
30
+ use Rack::HerokuEnv
31
+
32
+
33
+ Installation
34
+ ----
35
+
36
+ $ gem install rack-heroku_env
37
+
38
+
39
+ Testing
40
+ ----
41
+
42
+ $ gem install bundler
43
+ $ bundle install
44
+ $ bundle exec rspec spec/rack-heroku_env_spec.rb
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ module Rack
2
+ class HerokuEnv
3
+ VERSION = "0.0.1"
4
+
5
+ VARIABLE_NAMES = {
6
+ 'HTTP_X_HEROKU_DYNOS_IN_USE' => 'X-Heroku-Dynos-In-Use',
7
+ 'HTTP_X_HEROKU_QUEUE_DEPTH' => 'X-Heroku-Queue-Depth',
8
+ 'HTTP_X_HEROKU_QUEUE_WAIT_TIME' => 'X-Heroku-Queue-Wait-Time',
9
+ }
10
+
11
+ def initialize(app)
12
+ @app = app
13
+ end
14
+
15
+ def call(env)
16
+ response = @app.call(env)
17
+
18
+ VARIABLE_NAMES.each do |variable_name, header_name|
19
+ response[1][header_name] = env[variable_name] if env[variable_name]
20
+ end
21
+
22
+ response
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path("../lib/rack/heroku_env.rb", __FILE__)
3
+ version = File.read(lib)[/^\s*VERSION\s*=\s*(['"])(\d\.\d\.\d+)\1/, 2] #'# defeat messing with highlighting...
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rack-heroku_env"
7
+ s.version = version
8
+ s.authors = ["Junya Ogura"]
9
+ s.email = ["junyaogura@gmail.com"]
10
+ s.homepage = "https://github.com/juno/rack-heroku_env"
11
+ s.summary = %q{rack middleware for exposing Heroku environment variables}
12
+ s.description = %q{rack middleware for exposing Heroku environment variables}
13
+
14
+ s.rubyforge_project = "rack-heroku_env"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.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', '~> 1.3.2'
22
+
23
+ s.add_development_dependency 'rake', '~> 0.9.2'
24
+ s.add_development_dependency 'rspec', '~> 2.6.0'
25
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Rack::HerokuEnv do
4
+ let(:app) { lambda { |env| [200, { 'Content-Type' => 'text/plain' }, 'Hello'] } }
5
+ let(:env_vars) {
6
+ {
7
+ 'HTTP_X_HEROKU_DYNOS_IN_USE' => '1',
8
+ 'HTTP_X_HEROKU_QUEUE_DEPTH' => '2',
9
+ 'HTTP_X_HEROKU_QUEUE_WAIT_TIME' => '3',
10
+ }
11
+ }
12
+ let(:env) { Rack::MockRequest.env_for('/', env_vars) }
13
+
14
+ before { _, @headers, _ = Rack::HerokuEnv.new(app).call(env) }
15
+
16
+ it 'adds X-Heroku-Dynos-In-Use response header' do
17
+ @headers.should be_include('X-Heroku-Dynos-In-Use')
18
+ end
19
+
20
+ it 'adds X-Heroku-Queue-Depth response header' do
21
+ @headers.should be_include('X-Heroku-Queue-Depth')
22
+ end
23
+
24
+ it 'adds X-Heroku-Queue-Wait-Time response header' do
25
+ @headers.should be_include('X-Heroku-Queue-Wait-Time')
26
+ end
27
+
28
+ it 'sets HTTP_X_HEROKU_DYNOS_IN_USE value to response header' do
29
+ @headers['X-Heroku-Dynos-In-Use'].should eq('1')
30
+ end
31
+
32
+ it 'sets HTTP_X_HEROKU_QUEUE_DEPTH value to response header' do
33
+ @headers['X-Heroku-Queue-Depth'].should eq('2')
34
+ end
35
+
36
+ it 'sets HTTP_X_HEROKU_QUEUE_WAIT_TIME value to response header' do
37
+ @headers['X-Heroku-Queue-Wait-Time'].should eq('3')
38
+ end
39
+ end
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+
3
+ Bundler.setup(:runtime, :test)
4
+ Bundler.require(:test)
5
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
6
+
7
+ require 'rack/heroku_env'
8
+ require 'rack/mock'
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-heroku_env
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Junya Ogura
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-12 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ requirement: &70320178971740 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.3.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70320178971740
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70320178971260 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.9.2
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70320178971260
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70320178970800 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.6.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70320178970800
47
+ description: rack middleware for exposing Heroku environment variables
48
+ email:
49
+ - junyaogura@gmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE
57
+ - README.md
58
+ - Rakefile
59
+ - lib/rack/heroku_env.rb
60
+ - rack-heroku_env.gemspec
61
+ - spec/rack-heroku_env_spec.rb
62
+ - spec/spec_helper.rb
63
+ homepage: https://github.com/juno/rack-heroku_env
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project: rack-heroku_env
83
+ rubygems_version: 1.8.6
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: rack middleware for exposing Heroku environment variables
87
+ test_files:
88
+ - spec/rack-heroku_env_spec.rb
89
+ - spec/spec_helper.rb