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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ced1acc516b045e072e95a29bf2f424be8543510
4
- data.tar.gz: 4e93b0e986a57f1b7e9f288fd53a7d6a9b0c820a
3
+ metadata.gz: 5977f59d6733b910a8564b39f3c75521ee279c90
4
+ data.tar.gz: e1b05563d422c97d65b53ca6f6cc12dc174eb100
5
5
  SHA512:
6
- metadata.gz: b19f7823cb0da59df873f10de8e73d3815ee1deadfbace4d6f95159a171ba62bd8306273db39f31a93ee564b08ceed48d0c42c0d013310c8ed2c3490cf78f3e6
7
- data.tar.gz: e7b34801c85c176b1a6e0243c501bdeda702dfa9a71f3a25a0b45e6e47d6e16bc357d638e3bba6c395320daff58602dca4f720f81c44396a6695713b2e97a9a3
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
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 1.9.3
5
+ - 1.9.2
6
+ - jruby-19mode
7
+ - rbx-19mode
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
- TODO: Write a gem description
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
- TODO: Write usage instructions here
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
@@ -22,6 +22,10 @@ module Rack
22
22
  environment :production, &block
23
23
  end
24
24
 
25
+ def environments *environments, &block
26
+ Builder.new(*environments,block).mount
27
+ end
28
+
25
29
  def environment environment, &block
26
30
  Builder.new(environment,block).mount
27
31
  end
@@ -2,8 +2,8 @@ module Rack
2
2
  module When
3
3
  class Builder
4
4
 
5
- def initialize env, block
6
- @env, @block = env, block
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') =~ /^#{@env.to_s.downcase}/
14
+ @envs.any? { |env| (ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development') =~ /^#{env.to_s.downcase}/ }
15
15
  end
16
16
 
17
17
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module When
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -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
@@ -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.environment env, &(block = -> { })
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.environment(env) { }
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.2
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-15 00:00:00.000000000 Z
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