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 +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +16 -0
- data/Rakefile +5 -0
- data/TODO +0 -0
- data/lib/rack-obama.rb +2 -0
- data/lib/rack-obama/obama.rb +23 -0
- data/lib/rack-obama/version.rb +7 -0
- data/spec/rack-obama/obama_spec.rb +42 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +8 -0
- data/tasks/spec.rb +6 -0
- metadata +78 -0
data/History.rdoc
ADDED
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
data/TODO
ADDED
File without changes
|
data/lib/rack-obama.rb
ADDED
@@ -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,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
data/spec/spec_helper.rb
ADDED
data/tasks/spec.rb
ADDED
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
|
+
|