rack-when 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b73f8a82cd00f596135764e8a2944bc4540ab425
4
+ data.tar.gz: d1e40d6b2049bf8436b7dc36e01e8f5dedb48922
5
+ SHA512:
6
+ metadata.gz: 814df7decc343898d7bdf64258e329708991bddf05c192587f0c6968b35d95517d9b7535c13a7f7ee0003100e42bbe29b94abb80440052f2cc80901c31bbece1
7
+ data.tar.gz: 29d286a876cc77eb36660ca7f3acbd74ee777a8522de073027934d367cd2f032e8688171a01c9964da187249508400458d93c2d2e8d0c106bf7f325b126deb1b
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rack-when.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jon Rowe
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::When
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Usage
6
+
7
+ TODO: Write usage instructions here
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'rack-when'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install rack-when
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 'Add 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 @@
1
+ require "bundler/gem_tasks"
data/lib/rack/when.rb ADDED
@@ -0,0 +1,31 @@
1
+ require "rack/when/version"
2
+ require "rack/when/builder"
3
+ require "rack/builder"
4
+
5
+ module Rack
6
+ module When
7
+ class << self
8
+
9
+ def development &block
10
+ environment :development, &block
11
+ end
12
+
13
+ def test &block
14
+ environment :test, &block
15
+ end
16
+
17
+ def staging &block
18
+ environment :staging, &block
19
+ end
20
+
21
+ def production &block
22
+ environment :production, &block
23
+ end
24
+
25
+ def environment environment, &block
26
+ Builder.new(environment,block).mount
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,19 @@
1
+ module Rack
2
+ module When
3
+ class Builder
4
+
5
+ def initialize env, &block
6
+ @env, @block = env, block
7
+ end
8
+
9
+ def mount
10
+ @block.call if has_matching_env?
11
+ end
12
+
13
+ def has_matching_env?
14
+ (ENV['RACK_ENV'] || ENV['RAILS_ENV'] || 'development') =~ /^#{@env.to_s.downcase}/
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ module When
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/rack-when.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rack/when/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rack-when"
8
+ spec.version = Rack::When::VERSION
9
+ spec.authors = ["Jon Rowe"]
10
+ spec.email = ["hello@jonrowe.co.uk"]
11
+ spec.description = %q{Simple gem to load rack middleware only in certain environments.}
12
+ spec.summary = %q{Simple gem to load rack middleware only in certain environments.}
13
+ spec.homepage = "https://github.com/JonRowe/rack-when"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = []
18
+ spec.test_files = spec.files.grep(%r{^(spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "rack"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec"
26
+
27
+ end
@@ -0,0 +1,68 @@
1
+ require 'rack/when/builder'
2
+
3
+ describe 'An environment sensitive rack builder' do
4
+
5
+ describe '#mount rack_up' do
6
+ let(:builder) { Rack::When::Builder.new @env, &block }
7
+ let(:block) { -> {} }
8
+ let(:mount_builder) { builder.mount }
9
+
10
+ it 'will run the block when enviroment matches' do
11
+ @env = :development
12
+ expect(block).to receive(:call)
13
+ mount_builder
14
+ end
15
+
16
+ it 'will run the block when enviroment matches regardless of case' do
17
+ @env = 'DeVelopment'
18
+ expect(block).to receive(:call)
19
+ mount_builder
20
+ end
21
+
22
+ it 'will run the block when enviroment matches partially' do
23
+ @env = :dev
24
+ expect(block).to receive(:call)
25
+ mount_builder
26
+ end
27
+
28
+ it 'will ignore the block on mismatch' do
29
+ @env = :staging
30
+ mount_builder
31
+ end
32
+ end
33
+
34
+ describe '#current_env_matches?' do
35
+ shared_examples_for 'matching environment' do
36
+ it 'is true when matched' do
37
+ expect(Rack::When::Builder.new :development ).to have_matching_env
38
+ expect(Rack::When::Builder.new 'development').to have_matching_env
39
+ expect(Rack::When::Builder.new 'DeVelopment').to have_matching_env
40
+ end
41
+
42
+ it 'is true when matched as partial' do
43
+ expect(Rack::When::Builder.new :dev ).to have_matching_env
44
+ expect(Rack::When::Builder.new 'dev').to have_matching_env
45
+ end
46
+
47
+ it 'is false when mismatched' do
48
+ expect(Rack::When::Builder.new :staging).to_not have_matching_env
49
+ end
50
+ end
51
+
52
+ context 'environment set by RACK_ENV' do
53
+ before { ENV['RACK_ENV'] == 'development' }
54
+
55
+ it_should_behave_like 'matching environment'
56
+ end
57
+
58
+ context 'environment set by RAILS_ENV' do
59
+ before { ENV['RAILS_ENV'] == 'development' }
60
+
61
+ it_should_behave_like 'matching environment'
62
+ end
63
+
64
+ context 'environment not set' do
65
+ it_should_behave_like 'matching environment'
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,37 @@
1
+ require 'rack/when'
2
+
3
+ describe 'setting up for environments' do
4
+ [:development, :test, :staging, :production].each do |env|
5
+ before do
6
+ allow(Rack::When::Builder).to receive(:new).and_return(builder)
7
+ end
8
+
9
+ let(:builder) { double "builder", mount: nil }
10
+ let(:block) { double "block" }
11
+
12
+ context "implicit #{env}" do
13
+ it 'sets up a builder with the environment and the current context as rackup' do
14
+ Rack::When.send env, &(block = -> { })
15
+ expect(Rack::When::Builder).to have_received(:new).with(env.to_sym,block)
16
+ end
17
+
18
+ it 'mounts the builder with caller as rackup' do
19
+ Rack::When.send(env) { }
20
+ expect(builder).to have_received(:mount)
21
+ end
22
+ end
23
+
24
+ context "explicit #{env}" do
25
+ it 'sets up a builder with the environment and the current context as rackup' do
26
+ Rack::When.environment env, &(block = -> { })
27
+ expect(Rack::When::Builder).to have_received(:new).with(env.to_sym,block)
28
+ end
29
+
30
+ it 'mounts the builder with caller as rackup' do
31
+ Rack::When.environment(env) { }
32
+ expect(builder).to have_received(:mount)
33
+ end
34
+ end
35
+
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-when
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jon Rowe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDVjCCAj6gAwIBAgIBADANBgkqhkiG9w0BAQUFADBRMQ4wDAYDVQQDDAVoZWxs
14
+ bzEXMBUGCgmSJomT8ixkARkWB2pvbnJvd2UxEjAQBgoJkiaJk/IsZAEZFgJjbzES
15
+ MBAGCgmSJomT8ixkARkWAnVrMB4XDTEzMDIwMzA4MTgwNloXDTE0MDIwMzA4MTgw
16
+ NlowUTEOMAwGA1UEAwwFaGVsbG8xFzAVBgoJkiaJk/IsZAEZFgdqb25yb3dlMRIw
17
+ EAYKCZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJ1azCCASIwDQYJKoZI
18
+ hvcNAQEBBQADggEPADCCAQoCggEBAMhs6ng/SRrYfG7RtQx8liJTZs8tpz7PBnlH
19
+ qyOwuU0weJc7nh6C9C8LGyJzpkbjJJo1rfTMg7huDyL14Py82dfMDomApif8jNNI
20
+ 8KtviAgB1DrWq0fCDLtu/M77+yuVV3OhDdrAFaBkT/euvdJ8cAKrLxbJ+klgvrcB
21
+ FK+c4PUV3/zBKghe0l7FuDhyQCsuLNDbWyFvDS97tPjeN6yWuszwg22vZMDdsuzN
22
+ Cj3M4LLSkbrt+AOUcysEJxI4t6uv2U1bRzHsDfAF0RI/Q7OMtUr+Dtz/2YJ47KKs
23
+ 51ZRjLLGHd10XrIfFSfGyJj1dMbDgLsEBj1sFH4e6dy7gau8TaUCAwEAAaM5MDcw
24
+ CQYDVR0TBAIwADAdBgNVHQ4EFgQULu5JH2g7RAjoXaZt+fbrfNDI9IkwCwYDVR0P
25
+ BAQDAgSwMA0GCSqGSIb3DQEBBQUAA4IBAQAf5A4kB769DPKGjPZ++v42FwVi7X7v
26
+ RpufPs6R4YHyzHXaJmAqnhleZhVJijBgsdb2SigNRbg+IK8XYHg7jkonMgO8OS3D
27
+ C6w8VB5bI0PqyDOwCGcQkYHYlZZWCghAyBTSBowHAekMb9V3QjJtJ8XkizjshETO
28
+ ZCVI2AObjlJi8I10aK2tSo9sv2riCKZ92BVSM13zYWn+C/eCP/m9BDiw37UQtuQq
29
+ 2feWfO4gCNmvfFjULOAYHq9JHEjN5SLSXvj5HdSnDcCyIfJKn5Ya3JahWQaWIsXf
30
+ /NPE/mB57TOwj+d7XUa2NC4HUadF8R51IYEcIB0PpIEzJlKtfXFcOZxO
31
+ -----END CERTIFICATE-----
32
+ date: 2013-07-15 00:00:00.000000000 Z
33
+ dependencies:
34
+ - !ruby/object:Gem::Dependency
35
+ name: rack
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ type: :runtime
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
49
+ name: bundler
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: rspec
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ description: Simple gem to load rack middleware only in certain environments.
91
+ email:
92
+ - hello@jonrowe.co.uk
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - .gitignore
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - lib/rack/when.rb
103
+ - lib/rack/when/builder.rb
104
+ - lib/rack/when/version.rb
105
+ - rack-when.gemspec
106
+ - spec/rack/when/builder_spec.rb
107
+ - spec/rack/when_spec.rb
108
+ homepage: https://github.com/JonRowe/rack-when
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.0.3
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Simple gem to load rack middleware only in certain environments.
132
+ test_files:
133
+ - spec/rack/when/builder_spec.rb
134
+ - spec/rack/when_spec.rb
metadata.gz.sig ADDED
Binary file