rack-env 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/examples/sample-sinatra-application/.env +1 -0
- data/examples/sample-sinatra-application/Gemfile +4 -0
- data/examples/sample-sinatra-application/app.rb +8 -0
- data/examples/sample-sinatra-application/config.ru +5 -0
- data/lib/rack/env.rb +1 -1
- data/lib/rack/env/version.rb +1 -1
- data/spec/rack/env_spec.rb +47 -33
- data/spec/tmp/.env +4 -1
- data/spec/tmp/.envfile +4 -1
- metadata +8 -4
data/README.md
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
FOO=bar
|
data/lib/rack/env.rb
CHANGED
@@ -4,7 +4,6 @@ require "rack/env/version"
|
|
4
4
|
|
5
5
|
module Rack
|
6
6
|
class Env
|
7
|
-
|
8
7
|
def initialize(app, options = {})
|
9
8
|
@app = app
|
10
9
|
@options = options
|
@@ -30,6 +29,7 @@ module Rack
|
|
30
29
|
|
31
30
|
def read_env_file(envfile)
|
32
31
|
::File.readlines(envfile).each {|line|
|
32
|
+
next if line.chomp == "" || line =~ /^#/
|
33
33
|
key, value = line.chomp.split('=')
|
34
34
|
ENV[key] = value
|
35
35
|
} if ::File.exist?(envfile)
|
data/lib/rack/env/version.rb
CHANGED
data/spec/rack/env_spec.rb
CHANGED
@@ -1,37 +1,39 @@
|
|
1
1
|
require File.dirname(File.dirname(__FILE__)) + '/spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
CURRENT_DIR = Dir.getwd
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
before do
|
9
|
-
# move current_dir as ./spec
|
10
|
-
Dir::chdir(File.dirname(File.dirname(__FILE__)) + '/tmp')
|
5
|
+
def without_rack_env_app
|
6
|
+
Rack::Builder.new do
|
7
|
+
run TestRackApp.new
|
11
8
|
end
|
9
|
+
end
|
12
10
|
|
13
|
-
|
14
|
-
|
11
|
+
def rack_env_app
|
12
|
+
Rack::Builder.new do
|
13
|
+
use Rack::Env
|
14
|
+
run TestRackApp.new
|
15
15
|
end
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def rack_env_app_with_argument
|
19
|
+
Rack::Builder.new do
|
20
|
+
use Rack::Env, envfile: ".envfile"
|
21
|
+
run TestRackApp.new
|
21
22
|
end
|
23
|
+
end
|
22
24
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
describe 'Rack::Env' do
|
26
|
+
include Rack::Test::Methods
|
27
|
+
|
28
|
+
let(:request) { get '/' }
|
29
|
+
|
30
|
+
before do
|
31
|
+
# move current_dir to ./spec/tmp as root_dir
|
32
|
+
Dir::chdir(File.dirname(File.dirname(__FILE__)) + '/tmp')
|
28
33
|
end
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
use Rack::Env, envfile: ".envfile"
|
33
|
-
run TestRackApp.new
|
34
|
-
end
|
35
|
+
after(:all) do
|
36
|
+
Dir::chdir(CURRENT_DIR)
|
35
37
|
end
|
36
38
|
|
37
39
|
context "When not using Rack::Env" do
|
@@ -39,32 +41,44 @@ describe 'Rack::Env' do
|
|
39
41
|
without_rack_env_app
|
40
42
|
end
|
41
43
|
|
42
|
-
it "should
|
43
|
-
|
44
|
+
it "should not load environment variable" do
|
45
|
+
request
|
44
46
|
expect(ENV['FOO']).to eq nil
|
45
47
|
end
|
46
48
|
end
|
47
49
|
|
48
50
|
context "When using Rack::Env" do
|
49
|
-
context "
|
51
|
+
context "default envfile" do
|
50
52
|
def app
|
51
53
|
rack_env_app
|
52
54
|
end
|
53
55
|
|
54
|
-
it "should
|
55
|
-
|
56
|
-
|
56
|
+
it "should ignore empty line and commented out line" do
|
57
|
+
expect{
|
58
|
+
request
|
59
|
+
}.to change{ ENV.size }.by(2)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should load environment variable" do
|
63
|
+
request
|
64
|
+
expect(ENV['JAPAN']).to eq "Tokyo"
|
57
65
|
end
|
58
66
|
end
|
59
67
|
|
60
|
-
context "
|
68
|
+
context "specified envfile" do
|
61
69
|
def app
|
62
70
|
rack_env_app_with_argument
|
63
71
|
end
|
64
72
|
|
65
|
-
it "should
|
66
|
-
|
67
|
-
|
73
|
+
it "should ignore empty line and commented out line" do
|
74
|
+
expect{
|
75
|
+
request
|
76
|
+
}.to change{ ENV.size }.by(2)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should load environment variable" do
|
80
|
+
request
|
81
|
+
expect(ENV['INDIA']).to eq "Delhi"
|
68
82
|
end
|
69
83
|
end
|
70
84
|
end
|
data/spec/tmp/.env
CHANGED
data/spec/tmp/.envfile
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-env
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -89,6 +89,10 @@ files:
|
|
89
89
|
- LICENSE
|
90
90
|
- README.md
|
91
91
|
- Rakefile
|
92
|
+
- examples/sample-sinatra-application/.env
|
93
|
+
- examples/sample-sinatra-application/Gemfile
|
94
|
+
- examples/sample-sinatra-application/app.rb
|
95
|
+
- examples/sample-sinatra-application/config.ru
|
92
96
|
- lib/rack/env.rb
|
93
97
|
- lib/rack/env/version.rb
|
94
98
|
- rack-env.gemspec
|
@@ -110,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
110
114
|
version: '0'
|
111
115
|
segments:
|
112
116
|
- 0
|
113
|
-
hash: -
|
117
|
+
hash: -1732855213985109025
|
114
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
119
|
none: false
|
116
120
|
requirements:
|
@@ -119,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
123
|
version: '0'
|
120
124
|
segments:
|
121
125
|
- 0
|
122
|
-
hash: -
|
126
|
+
hash: -1732855213985109025
|
123
127
|
requirements: []
|
124
128
|
rubyforge_project:
|
125
129
|
rubygems_version: 1.8.23
|