kissifer-rack-reflect-env 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 kissifer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = rack-reflect-env
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 kissifer. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "rack-reflect-env"
8
+ gem.summary = %Q{Stops downsteam processing, dumps env.inspect into the reply body, sets Content-Type if given. Debug only.}
9
+ gem.email = "tierneydrchris@gmail.com"
10
+ gem.homepage = "http://github.com/kissifer/rack-reflect-env"
11
+ gem.authors = ["kissifer"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'spec/rake/spectask'
20
+ Spec::Rake::SpecTask.new(:spec) do |spec|
21
+ spec.libs << 'lib' << 'spec'
22
+ spec.spec_files = FileList['spec/**/*_spec.rb']
23
+ spec.spec_opts = ['--options spec/spec.opts']
24
+ end
25
+
26
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.pattern = 'spec/**/*_spec.rb'
29
+ spec.rcov = true
30
+ end
31
+
32
+
33
+ task :default => :spec
34
+
35
+ require 'rake/rdoctask'
36
+ Rake::RDocTask.new do |rdoc|
37
+ if File.exist?('VERSION.yml')
38
+ config = YAML.load(File.read('VERSION.yml'))
39
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
40
+ else
41
+ version = ""
42
+ end
43
+
44
+ rdoc.rdoc_dir = 'rdoc'
45
+ rdoc.title = "rack-reflect-env #{version}"
46
+ rdoc.rdoc_files.include('README*')
47
+ rdoc.rdoc_files.include('lib/**/*.rb')
48
+ end
49
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.2
@@ -0,0 +1,21 @@
1
+ module Rack
2
+ class ReflectEnv
3
+ def initialize(app, opts = {})
4
+ opts = {:type => 'text/plain'}.merge(opts)
5
+ @type = opts[:type]
6
+ @keys = opts[:keys]
7
+ end
8
+
9
+ def call(env)
10
+ headers = {}
11
+ headers['Content-Type'] = @type
12
+ env = env.reject {|k,v| !@keys.include?(k)} if @keys
13
+ [200, headers, [env.inspect]]
14
+ end
15
+
16
+ def self.app(opts = {})
17
+ new(nil, opts)
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,47 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{rack-reflect-env}
5
+ s.version = "0.1.2"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["kissifer"]
9
+ s.date = %q{2009-06-12}
10
+ s.email = %q{tierneydrchris@gmail.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "lib/rack/reflect-env.rb",
23
+ "rack-reflect-env.gemspec",
24
+ "spec/rack-reflect-env_spec.rb",
25
+ "spec/spec.opts",
26
+ "spec/spec_helper.rb"
27
+ ]
28
+ s.homepage = %q{http://github.com/kissifer/rack-reflect-env}
29
+ s.rdoc_options = ["--charset=UTF-8"]
30
+ s.require_paths = ["lib"]
31
+ s.rubygems_version = %q{1.3.4}
32
+ s.summary = %q{Stops downsteam processing, dumps env.inspect into the reply body, sets Content-Type if given. Debug only.}
33
+ s.test_files = [
34
+ "spec/rack-reflect-env_spec.rb",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
43
+ else
44
+ end
45
+ else
46
+ end
47
+ end
@@ -0,0 +1,63 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Rack::ReflectEnv" do
4
+ context "when created as middleware" do
5
+ it "should dump env.inspect into the reply body" do
6
+ reflect = Rack::ReflectEnv.new("app")
7
+ env = Rack::MockRequest.env_for("/foo")
8
+ status, headers, body = reflect.call(env)
9
+ status.should == 200
10
+ headers['Content-Type'].should == 'text/plain'
11
+ body.should == [env.inspect]
12
+ end
13
+
14
+ it "should not call downstream middleware" do
15
+ app = "app"
16
+ reflect = Rack::ReflectEnv.new(app)
17
+ app.should_not_receive(:call)
18
+ reflect.call("env")
19
+ end
20
+
21
+ it "should set the Content-Type if required" do
22
+ reflect = Rack::ReflectEnv.new("app", :type => "foo")
23
+ status, headers, body = reflect.call("env")
24
+ headers['Content-Type'].should == "foo"
25
+ end
26
+
27
+ it "should filter the env keys if required" do
28
+ keys = ["PATH_INFO", "SCRIPT_NAME"]
29
+ reflect = Rack::ReflectEnv.new("app", :keys => keys)
30
+ env = Rack::MockRequest.env_for("/foo")
31
+ status, headers, body = reflect.call(env)
32
+ filtered = env.reject {|k,v| !keys.include?(k)}
33
+ body.should == [filtered.inspect]
34
+ end
35
+ end
36
+
37
+ context "when created as an app" do
38
+ it "should dump env.inspect into the reply body" do
39
+ reflect = Rack::ReflectEnv.app
40
+ env = Rack::MockRequest.env_for("/foo")
41
+ status, headers, body = reflect.call(env)
42
+ status.should == 200
43
+ headers['Content-Type'].should == 'text/plain'
44
+ body.should == [env.inspect]
45
+ end
46
+
47
+ it "should set the Content-Type if required" do
48
+ reflect = Rack::ReflectEnv.app(:type => "foo")
49
+ status, headers, body = reflect.call("env")
50
+ headers['Content-Type'].should == "foo"
51
+ end
52
+
53
+ it "should filter the env keys if required" do
54
+ keys = ["PATH_INFO", "SCRIPT_NAME"]
55
+ reflect = Rack::ReflectEnv.app(:keys => keys)
56
+ env = Rack::MockRequest.env_for("/foo")
57
+ status, headers, body = reflect.call(env)
58
+ filtered = env.reject {|k,v| !keys.include?(k)}
59
+ body.should == [filtered.inspect]
60
+ end
61
+
62
+ end
63
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format nested
@@ -0,0 +1,11 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'rack/mock'
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
7
+ require 'rack/reflect-env'
8
+
9
+ Spec::Runner.configure do |config|
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kissifer-rack-reflect-env
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - kissifer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-12 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: tierneydrchris@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - VERSION
32
+ - lib/rack/reflect-env.rb
33
+ - rack-reflect-env.gemspec
34
+ - spec/rack-reflect-env_spec.rb
35
+ - spec/spec.opts
36
+ - spec/spec_helper.rb
37
+ has_rdoc: false
38
+ homepage: http://github.com/kissifer/rack-reflect-env
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project:
59
+ rubygems_version: 1.2.0
60
+ signing_key:
61
+ specification_version: 3
62
+ summary: Stops downsteam processing, dumps env.inspect into the reply body, sets Content-Type if given. Debug only.
63
+ test_files:
64
+ - spec/rack-reflect-env_spec.rb
65
+ - spec/spec_helper.rb