rack-env 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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ # https://github.com/travis-ci/travis-ci/wiki/.travis.yml-options
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-env.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Kohei Hasegawa
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # rack-env
2
+
3
+ Sets .env variables
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rack-env'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rack-env
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+
7
+ desc 'Default: run specs.'
8
+ task :default => :spec
9
+
10
+ RSpec::Core::RakeTask.new(:spec) do |spec|
11
+ spec.pattern = FileList['spec/**/*_spec.rb']
12
+ end
data/lib/rack/env.rb ADDED
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require "rack/env/version"
4
+
5
+ module Rack
6
+ class Env
7
+
8
+ def initialize(app, options = {})
9
+ @app = app
10
+ @options = options
11
+ end
12
+
13
+ def call(env)
14
+ set_env
15
+ @app.call(env)
16
+ end
17
+
18
+ private
19
+ def set_env
20
+ if @options[:envfile]
21
+ read_env_file(@options[:envfile])
22
+ else
23
+ read_env_file(default_env_file)
24
+ end
25
+ end
26
+
27
+ def default_env_file
28
+ ::File.join(Dir.getwd, '.env')
29
+ end
30
+
31
+ def read_env_file(envfile)
32
+ ::File.readlines(envfile).each {|line|
33
+ key, value = line.chomp.split('=')
34
+ ENV[key] = value
35
+ } if ::File.exist?(envfile)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class Env
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/rack-env.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/rack/env/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Kohei Hasegawa"]
6
+ gem.email = ["ameutau@gmail.com"]
7
+ gem.description = %q{Set .env valirables}
8
+ gem.summary = %q{Set .env valirables}
9
+ gem.homepage = "http://github.com/banyan/rack-env"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "rack-env"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Rack::Env::VERSION
17
+
18
+ gem.add_development_dependency "rspec", "~> 2.11.0"
19
+ gem.add_development_dependency 'rake', '>= 0.9.2.2'
20
+ gem.add_development_dependency "rack", '>= 1.4.1'
21
+ gem.add_development_dependency 'rack-test', '>= 0.6.1'
22
+ end
data/spec/.env ADDED
@@ -0,0 +1 @@
1
+ FOO=bar
data/spec/.envfile ADDED
@@ -0,0 +1 @@
1
+ BAZ=qux
@@ -0,0 +1,71 @@
1
+ require File.dirname(File.dirname(__FILE__)) + '/spec_helper'
2
+
3
+ current_dir = Dir.getwd
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__)))
11
+ end
12
+
13
+ after(:all) do
14
+ Dir::chdir(current_dir)
15
+ end
16
+
17
+ def without_rack_env_app
18
+ Rack::Builder.new do
19
+ run TestRackApp.new
20
+ end
21
+ end
22
+
23
+ def rack_env_app
24
+ Rack::Builder.new do
25
+ use Rack::Env
26
+ run TestRackApp.new
27
+ end
28
+ end
29
+
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
+ end
36
+
37
+ context "When not using Rack::Env" do
38
+ def app
39
+ without_rack_env_app
40
+ end
41
+
42
+ it "should ENV['FOO'] is nil" do
43
+ get '/'
44
+ ENV['FOO'].should be_nil
45
+ end
46
+ end
47
+
48
+ context "When using Rack::Env" do
49
+ context "without argument" do
50
+ def app
51
+ rack_env_app
52
+ end
53
+
54
+ it "should ENV['FOO'] == 'bar'" do
55
+ get '/'
56
+ ENV['FOO'].should == "bar"
57
+ end
58
+ end
59
+
60
+ context "with argument" do
61
+ def app
62
+ rack_env_app_with_argument
63
+ end
64
+
65
+ it "should ENV['BAZ'] == 'qux'" do
66
+ get '/'
67
+ ENV['BAZ'].should == "qux"
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,10 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $:.unshift(File.dirname(__FILE__))
3
+
4
+ %w(rack rack/test rack/env rspec).each {|f| require f }
5
+
6
+ class TestRackApp
7
+ def call(env)
8
+ [200, {"Content-Type" => "text/html"}, ["hi"]]
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-env
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kohei Hasegawa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.11.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.11.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.9.2.2
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.2.2
46
+ - !ruby/object:Gem::Dependency
47
+ name: rack
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 1.4.1
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.4.1
62
+ - !ruby/object:Gem::Dependency
63
+ name: rack-test
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.6.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.6.1
78
+ description: Set .env valirables
79
+ email:
80
+ - ameutau@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - .rspec
87
+ - .travis.yml
88
+ - Gemfile
89
+ - LICENSE
90
+ - README.md
91
+ - Rakefile
92
+ - lib/rack/env.rb
93
+ - lib/rack/env/version.rb
94
+ - rack-env.gemspec
95
+ - spec/.env
96
+ - spec/.envfile
97
+ - spec/rack/env_spec.rb
98
+ - spec/spec_helper.rb
99
+ homepage: http://github.com/banyan/rack-env
100
+ licenses: []
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ segments:
112
+ - 0
113
+ hash: -1633070895306891892
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ segments:
121
+ - 0
122
+ hash: -1633070895306891892
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 1.8.23
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: Set .env valirables
129
+ test_files:
130
+ - spec/.env
131
+ - spec/.envfile
132
+ - spec/rack/env_spec.rb
133
+ - spec/spec_helper.rb