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 CHANGED
@@ -52,7 +52,7 @@ end
52
52
  ```
53
53
  # config.ru
54
54
  Rack::Builder.new
55
- use Rack::Env, envfile: 'config/.env' if ENV['RACK_ENV'] == 'development'
55
+ use Rack::Env, envfile: 'somewhere/to/.env.development' if ENV['RACK_ENV'] == 'development'
56
56
  run MyApplication.new
57
57
  end
58
58
  ```
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ gem 'sinatra'
4
+ gem 'rack-env', path: "/Users/banyan/git/rack-env"
@@ -0,0 +1,8 @@
1
+ require 'sinatra'
2
+
3
+ require 'rack/env'
4
+ use Rack::Env
5
+
6
+ get '/' do
7
+ ENV['FOO']
8
+ end
@@ -0,0 +1,5 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $:.unshift(File.dirname(__FILE__))
3
+
4
+ require './app.rb'
5
+ run Sinatra::Application
@@ -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)
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Env
3
- VERSION = "0.0.3"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -1,37 +1,39 @@
1
1
  require File.dirname(File.dirname(__FILE__)) + '/spec_helper'
2
2
 
3
- current_dir = Dir.getwd
3
+ CURRENT_DIR = Dir.getwd
4
4
 
5
- describe 'Rack::Env' do
6
- include Rack::Test::Methods
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
- after(:all) do
14
- Dir::chdir(current_dir)
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
- def without_rack_env_app
18
- Rack::Builder.new do
19
- run TestRackApp.new
20
- end
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
- def rack_env_app
24
- Rack::Builder.new do
25
- use Rack::Env
26
- run TestRackApp.new
27
- end
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
- def rack_env_app_with_argument
31
- Rack::Builder.new do
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 ENV['FOO'] is nil" do
43
- get '/'
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 "without argument" do
51
+ context "default envfile" do
50
52
  def app
51
53
  rack_env_app
52
54
  end
53
55
 
54
- it "should ENV['FOO'] == 'bar'" do
55
- get '/'
56
- expect(ENV['FOO']).to eq "bar"
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 "with argument" do
68
+ context "specified envfile" do
61
69
  def app
62
70
  rack_env_app_with_argument
63
71
  end
64
72
 
65
- it "should ENV['BAZ'] == 'qux'" do
66
- get '/'
67
- expect(ENV['BAZ']).to eq "qux"
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
@@ -1 +1,4 @@
1
- FOO=bar
1
+ JAPAN=Tokyo
2
+
3
+ BRAZIL=Brasilia
4
+ # AUSTRARIA=Canberra
@@ -1 +1,4 @@
1
- BAZ=qux
1
+ ENGLAND=London
2
+
3
+ INDIA=Delhi
4
+ # THAILAND=Bangkok
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.3
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-23 00:00:00.000000000 Z
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: -1717073382629567647
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: -1717073382629567647
126
+ hash: -1732855213985109025
123
127
  requirements: []
124
128
  rubyforge_project:
125
129
  rubygems_version: 1.8.23