rack-obama 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ === 0.1.0 / 2009-10-16
2
+
3
+ * Initial version copied from the CodeRack submission
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Simon Harris
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,16 @@
1
+ = rack-obama
2
+
3
+ Rack middleware that accepts all nobel-prize/peace requests.
4
+
5
+ Somewhere in your Rack configuration (eg. config.ru) add:
6
+
7
+ require 'rack-obama'
8
+ use Rack::Obama
9
+
10
+ Then hit your application with the appropriate request:
11
+
12
+ > curl -i -H "Content-Type: nobel-prize/peace" http://localhost:9292/
13
+
14
+ HTTP/1.1 202 Accepted
15
+ Content-Length: 0
16
+ Content-Type: nobel-prize/pace
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ Dir["tasks/**/*.rb"].each do |task_file|
2
+ require task_file
3
+ end
4
+
5
+ task :default => [ :spec ]
data/TODO ADDED
File without changes
data/lib/rack-obama.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'rack-obama/obama'
2
+ require 'rack-obama/version'
@@ -0,0 +1,23 @@
1
+ require 'rack'
2
+
3
+ module Rack
4
+
5
+ class Obama
6
+
7
+ CONTENT_TYPE = "nobel-prize/peace".freeze
8
+
9
+ def initialize(app)
10
+ @app = app
11
+ end
12
+
13
+ def call(env)
14
+ if env["CONTENT_TYPE"] == CONTENT_TYPE
15
+ ["202 Accepted", {"Content-Type" => CONTENT_TYPE, "Content-Length" => "0"}, []]
16
+ else
17
+ @app.call(env)
18
+ end
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,7 @@
1
+ module Rack
2
+
3
+ class Obama
4
+ VERSION = "0.1.0".freeze
5
+ end
6
+
7
+ end
@@ -0,0 +1,42 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Rack::Obama do
4
+
5
+ def do_call(content_type, request_method, &block)
6
+ request = Rack::MockRequest.env_for("/", "CONTENT_TYPE" => content_type, :method => request_method)
7
+ @response = Rack::Obama.new(block).call(request)
8
+ end
9
+
10
+ %w{POST GET PUT DELETE HEAD}.each do |method|
11
+
12
+ describe method do
13
+
14
+ describe "text/html" do
15
+
16
+ before do
17
+ do_call("text/html", method) { |env| :result }
18
+ end
19
+
20
+ it "forwards the request for processing" do
21
+ @response.should == :result
22
+ end
23
+
24
+ end
25
+
26
+ describe "nobel-prize/peace" do
27
+
28
+ before do
29
+ do_call("nobel-prize/peace", method) { |env| fail "Should not forward request for processing" }
30
+ end
31
+
32
+ it "is accepted" do
33
+ @response.should == ["202 Accepted", {"Content-Type" => "nobel-prize/peace", "Content-Length" => "0"}, []]
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+
42
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,3 @@
1
+ --colour
2
+ --loadby random
3
+ --backtrace
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+ require 'rack/mock'
3
+
4
+ # Support running specs with "rake spec" and "spec"
5
+ lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+
8
+ require 'rack-obama'
data/tasks/spec.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "spec/rake/spectask"
2
+
3
+ desc "Run specifications"
4
+ Spec::Rake::SpecTask.new(:spec) do |t|
5
+ t.spec_opts << "--options" << "spec/spec.opts" if File.exists?("spec/spec.opts")
6
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-obama
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Simon Harris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-16 00:00:00 +11:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rack
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Rack middleware that accepts all nobel-prize/peace requests
26
+ email: haruki.zaemon@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ - History.rdoc
34
+ - TODO
35
+ - LICENSE
36
+ files:
37
+ - lib/rack-obama/obama.rb
38
+ - lib/rack-obama/version.rb
39
+ - lib/rack-obama.rb
40
+ - spec/rack-obama/obama_spec.rb
41
+ - spec/spec.opts
42
+ - spec/spec_helper.rb
43
+ - tasks/spec.rb
44
+ - Rakefile
45
+ - README.rdoc
46
+ - History.rdoc
47
+ - TODO
48
+ - LICENSE
49
+ has_rdoc: true
50
+ homepage: http://github.com/harukizaemon/rack-obama
51
+ licenses: []
52
+
53
+ post_install_message:
54
+ rdoc_options: []
55
+
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.3.5
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Rack middleware that accepts all nobel-prize/peace requests
77
+ test_files: []
78
+