rack-when 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.travis.yml +7 -0
- data/README.md +39 -2
- data/lib/rack/when.rb +4 -0
- data/lib/rack/when/builder.rb +3 -3
- data/lib/rack/when/version.rb +1 -1
- data/spec/rack/when/builder_spec.rb +10 -0
- data/spec/rack/when_spec.rb +15 -2
- metadata +3 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5977f59d6733b910a8564b39f3c75521ee279c90
|
4
|
+
data.tar.gz: e1b05563d422c97d65b53ca6f6cc12dc174eb100
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af9b557c7e590ece682af13250a6ab1d55536a1fca23836068b58cdf8028b498aa63281c2129fa846842e87d78b10a91d2b950ed673035624854cb7a5b09844b
|
7
|
+
data.tar.gz: b08fc92243948cf695483d342be345e1add37bc73bb298ad46462f05caf41858ce051e00977efe8bdd0b99aa3dd72d8f9225f06339ebe19f3136fd5748216577
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,10 +1,47 @@
|
|
1
1
|
# Rack::When
|
2
|
+
[![Build Status](https://secure.travis-ci.org/JonRowe/rack-when.png?branch=master)](http://travis-ci.org/JonRowe/rack-when) [![Code Climate](https://codeclimate.com/github/JonRowe/rack-when.png)](https://codeclimate.com/github/JonRowe/rack-when)
|
2
3
|
|
3
|
-
|
4
|
+
Shortcut handler for performing tasks in specific environments. Specific
|
5
|
+
environments can be set to run specific sections of code. I wrote this
|
6
|
+
to handle rack-middleware and as such it works in a `config.ru` but you
|
7
|
+
could use it to run anything.
|
8
|
+
|
9
|
+
The order of precedence for env is `ENV['RACK_ENV']` or `ENV['RAILS_ENV']`
|
10
|
+
but it defaults to `development`.
|
4
11
|
|
5
12
|
## Usage
|
6
13
|
|
7
|
-
|
14
|
+
In your `config.ru` do
|
15
|
+
|
16
|
+
```Ruby
|
17
|
+
Rack::When.development do
|
18
|
+
# Things you want done in development
|
19
|
+
use DevelopmentMiddleware
|
20
|
+
end
|
21
|
+
|
22
|
+
Rack::When.production do
|
23
|
+
# Things you want done in production
|
24
|
+
use ProductionMetricMaker
|
25
|
+
end
|
26
|
+
|
27
|
+
run MyApplication
|
28
|
+
```
|
29
|
+
|
30
|
+
You can also specify the enviroment directly if you would prefer:
|
31
|
+
|
32
|
+
```Ruby
|
33
|
+
Rack::When.environments :custom_env do
|
34
|
+
# My custom env code
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
38
|
+
and with multiple environments:
|
39
|
+
|
40
|
+
```Ruby
|
41
|
+
Rack::When.environments :custom_env, :another_custom_env do
|
42
|
+
# My custom env code
|
43
|
+
end
|
44
|
+
```
|
8
45
|
|
9
46
|
## Installation
|
10
47
|
|
data/lib/rack/when.rb
CHANGED
data/lib/rack/when/builder.rb
CHANGED
@@ -2,8 +2,8 @@ module Rack
|
|
2
2
|
module When
|
3
3
|
class Builder
|
4
4
|
|
5
|
-
def initialize
|
6
|
-
|
5
|
+
def initialize *args
|
6
|
+
*@envs, @block = args
|
7
7
|
end
|
8
8
|
|
9
9
|
def mount
|
@@ -11,7 +11,7 @@ module Rack
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def has_matching_env?
|
14
|
-
(ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development') =~ /^#{
|
14
|
+
@envs.any? { |env| (ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development') =~ /^#{env.to_s.downcase}/ }
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
data/lib/rack/when/version.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'rack/when/builder'
|
2
2
|
|
3
3
|
describe 'An environment sensitive rack builder' do
|
4
|
+
before do
|
5
|
+
stub_const("ENV",{})
|
6
|
+
end
|
4
7
|
|
5
8
|
describe '#mount rack_up' do
|
6
9
|
let(:builder) { Rack::When::Builder.new @env, block }
|
@@ -64,5 +67,12 @@ describe 'An environment sensitive rack builder' do
|
|
64
67
|
context 'environment not set' do
|
65
68
|
it_should_behave_like 'matching environment'
|
66
69
|
end
|
70
|
+
|
71
|
+
it 'matches when one of multiple envs match' do
|
72
|
+
ENV['RACK_ENV'] = 'custom'
|
73
|
+
expect(Rack::When::Builder.new :dev, :custom, double ).to have_matching_env
|
74
|
+
expect(Rack::When::Builder.new :custom, :test, double ).to have_matching_env
|
75
|
+
expect(Rack::When::Builder.new :dev, :test, double ).to_not have_matching_env
|
76
|
+
end
|
67
77
|
end
|
68
78
|
end
|
data/spec/rack/when_spec.rb
CHANGED
@@ -23,15 +23,28 @@ describe 'setting up for environments' do
|
|
23
23
|
|
24
24
|
context "explicit #{env}" do
|
25
25
|
it 'sets up a builder with the environment and the current context as rackup' do
|
26
|
-
Rack::When.
|
26
|
+
Rack::When.environments env, &(block = -> { })
|
27
27
|
expect(Rack::When::Builder).to have_received(:new).with(env.to_sym,block)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'mounts the builder with caller as rackup' do
|
31
|
-
Rack::When.
|
31
|
+
Rack::When.environments(env) { }
|
32
32
|
expect(builder).to have_received(:mount)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
37
|
+
|
38
|
+
context "mutiple envs" do
|
39
|
+
it 'sets up a builder with the environments and the current context as rackup' do
|
40
|
+
Rack::When.environments :one, :two, &(block = -> { })
|
41
|
+
expect(Rack::When::Builder).to have_received(:new).with(:one, :two, block)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'mounts the builder with caller as rackup' do
|
45
|
+
Rack::When.environments(:one, :two) { }
|
46
|
+
expect(builder).to have_received(:mount)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
37
50
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-when
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Rowe
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
2feWfO4gCNmvfFjULOAYHq9JHEjN5SLSXvj5HdSnDcCyIfJKn5Ya3JahWQaWIsXf
|
30
30
|
/NPE/mB57TOwj+d7XUa2NC4HUadF8R51IYEcIB0PpIEzJlKtfXFcOZxO
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2013-07-
|
32
|
+
date: 2013-07-16 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: rack
|
@@ -95,6 +95,7 @@ extensions: []
|
|
95
95
|
extra_rdoc_files: []
|
96
96
|
files:
|
97
97
|
- .gitignore
|
98
|
+
- .travis.yml
|
98
99
|
- Gemfile
|
99
100
|
- LICENSE.txt
|
100
101
|
- README.md
|
metadata.gz.sig
CHANGED
Binary file
|