rack-environment 1.0.0
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.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +45 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/lib/rack-environment.rb +1 -0
- data/lib/rack_environment.rb +45 -0
- data/rack-environment.gemspec +62 -0
- data/spec/config/environment.yml +2 -0
- data/spec/rack_environment_spec.rb +42 -0
- data/spec/rcov.opts +2 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +15 -0
- data/spec/test_application.rb +7 -0
- metadata +91 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 David Dollar
|
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.rdoc
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
= rack-environment
|
2
|
+
|
3
|
+
Rack::Environment is useful for getting ENVironment variables set for your
|
4
|
+
application.
|
5
|
+
|
6
|
+
A primary use This can help you to more closely simulate your Heroku environment in
|
7
|
+
development.
|
8
|
+
|
9
|
+
== Rails
|
10
|
+
|
11
|
+
# config/environments/development.rb
|
12
|
+
config.gem 'rack-environment'
|
13
|
+
config.middleware.use 'RackEnvironment'
|
14
|
+
|
15
|
+
# config/environment.yml
|
16
|
+
VARIABLE1: value1
|
17
|
+
VARIABLE2: value2
|
18
|
+
|
19
|
+
== Rack
|
20
|
+
|
21
|
+
# config.ru
|
22
|
+
Rack::Builder.new
|
23
|
+
use RackEnvironment if ENV['RACK_ENV'] == 'development'
|
24
|
+
run MyApplication.new
|
25
|
+
end
|
26
|
+
|
27
|
+
== Options
|
28
|
+
|
29
|
+
use RackEnvironment, :environment => { :ONE => 'one', 'two' => 'two' }
|
30
|
+
use RackEnvironment, :file => 'config/environment.yml'
|
31
|
+
|
32
|
+
== Note on Patches/Pull Requests
|
33
|
+
|
34
|
+
* 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.
|
38
|
+
* Commit, do not mess with rakefile, version, or history.
|
39
|
+
(if you want to have your own version, that is fine but
|
40
|
+
bump version in a commit by itself I can ignore when I pull)
|
41
|
+
* Send me a pull request. Bonus points for topic branches.
|
42
|
+
|
43
|
+
== Copyright
|
44
|
+
|
45
|
+
Copyright (c) 2009 David Dollar. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rack-environment"
|
8
|
+
gem.summary = %Q{Rack::Environment}
|
9
|
+
gem.description = %Q{Rack::Environment}
|
10
|
+
gem.email = "ddollar@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/ddollar/rack-environment"
|
12
|
+
gem.authors = ["David Dollar"]
|
13
|
+
|
14
|
+
gem.add_development_dependency "rspec"
|
15
|
+
gem.add_development_dependency "rack-test"
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
if File.exist?('VERSION')
|
41
|
+
version = File.read('VERSION')
|
42
|
+
else
|
43
|
+
version = ""
|
44
|
+
end
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "rack-environment #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'rack_environment'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class RackEnvironment
|
2
|
+
|
3
|
+
attr_reader :app, :options
|
4
|
+
|
5
|
+
def initialize(app, options={})
|
6
|
+
@app = app
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def call(env)
|
11
|
+
update_environment!
|
12
|
+
app.call(env)
|
13
|
+
end
|
14
|
+
|
15
|
+
private ######################################################################
|
16
|
+
|
17
|
+
def default_config_file
|
18
|
+
File.join(Dir.getwd, 'config', 'environment.yml')
|
19
|
+
end
|
20
|
+
|
21
|
+
def environment
|
22
|
+
normalize case
|
23
|
+
when options[:environment] then options[:environment]
|
24
|
+
when options[:file] then read_config_file(options[:file])
|
25
|
+
else read_config_file(default_config_file)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def normalize(environment)
|
30
|
+
environment.inject({}) do |hash, (key, value)|
|
31
|
+
hash.update(key.to_s.upcase => value)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def read_config_file(filename)
|
36
|
+
YAML::load_file(filename)
|
37
|
+
end
|
38
|
+
|
39
|
+
def update_environment!
|
40
|
+
environment.each do |key, value|
|
41
|
+
ENV[key] = value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{rack-environment}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["David Dollar"]
|
12
|
+
s.date = %q{2009-11-08}
|
13
|
+
s.description = %q{Rack::Environment}
|
14
|
+
s.email = %q{ddollar@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/rack-environment.rb",
|
27
|
+
"lib/rack_environment.rb",
|
28
|
+
"rack-environment.gemspec",
|
29
|
+
"spec/config/environment.yml",
|
30
|
+
"spec/rack_environment_spec.rb",
|
31
|
+
"spec/rcov.opts",
|
32
|
+
"spec/spec.opts",
|
33
|
+
"spec/spec_helper.rb",
|
34
|
+
"spec/test_application.rb"
|
35
|
+
]
|
36
|
+
s.homepage = %q{http://github.com/ddollar/rack-environment}
|
37
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
38
|
+
s.require_paths = ["lib"]
|
39
|
+
s.rubygems_version = %q{1.3.5}
|
40
|
+
s.summary = %q{Rack::Environment}
|
41
|
+
s.test_files = [
|
42
|
+
"spec/rack_environment_spec.rb",
|
43
|
+
"spec/spec_helper.rb",
|
44
|
+
"spec/test_application.rb"
|
45
|
+
]
|
46
|
+
|
47
|
+
if s.respond_to? :specification_version then
|
48
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<rack-test>, [">= 0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
57
|
+
end
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
60
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "RackEnvironment" do
|
4
|
+
include Rack::Test::Methods
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
get "/"
|
8
|
+
@environment = last_response.headers['X-Rack-Environment']
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "with specified config file" do
|
12
|
+
def app
|
13
|
+
Rack::Builder.new do
|
14
|
+
use RackEnvironment, :file => File.expand_path(File.dirname(__FILE__) + '/config/environment.yml')
|
15
|
+
run TestApplication.new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have the proper environment set" do
|
20
|
+
@environment['UPPER'].should == 'upper_value'
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should uppercase environment variables" do
|
24
|
+
@environment['lower'].should_not == 'lower_value'
|
25
|
+
@environment['LOWER'].should == 'lower_value'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "with specified environment" do
|
30
|
+
def app
|
31
|
+
Rack::Builder.new do
|
32
|
+
use RackEnvironment, :environment => { :ONE => 'one_value' }
|
33
|
+
run TestApplication.new
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have the proper environment set" do
|
38
|
+
@environment['ONE'].should == 'one_value'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/spec/rcov.opts
ADDED
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rack/test'
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
6
|
+
|
7
|
+
require 'spec'
|
8
|
+
require 'spec/autorun'
|
9
|
+
require 'test_application'
|
10
|
+
|
11
|
+
require 'rack_environment'
|
12
|
+
|
13
|
+
Spec::Runner.configure do |config|
|
14
|
+
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-environment
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Dollar
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-08 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rack-test
|
27
|
+
type: :development
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: Rack::Environment
|
36
|
+
email: ddollar@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- lib/rack-environment.rb
|
52
|
+
- lib/rack_environment.rb
|
53
|
+
- rack-environment.gemspec
|
54
|
+
- spec/config/environment.yml
|
55
|
+
- spec/rack_environment_spec.rb
|
56
|
+
- spec/rcov.opts
|
57
|
+
- spec/spec.opts
|
58
|
+
- spec/spec_helper.rb
|
59
|
+
- spec/test_application.rb
|
60
|
+
has_rdoc: true
|
61
|
+
homepage: http://github.com/ddollar/rack-environment
|
62
|
+
licenses: []
|
63
|
+
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options:
|
66
|
+
- --charset=UTF-8
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
version:
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 1.3.5
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Rack::Environment
|
88
|
+
test_files:
|
89
|
+
- spec/rack_environment_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- spec/test_application.rb
|