rack-api 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/examples/config.ru +5 -2
- data/lib/rack/api/controller.rb +1 -1
- data/lib/rack/api/formatter/base.rb +3 -2
- data/lib/rack/api/version.rb +1 -1
- data/spec/rack-api/format_spec.rb +26 -0
- metadata +20 -20
data/Gemfile.lock
CHANGED
data/examples/config.ru
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
$:.push(File.dirname(__FILE__) + "/../lib")
|
2
2
|
|
3
|
-
# Just run `
|
4
|
-
# `curl -u admin:test http://localhost:2345
|
3
|
+
# Just run `rackup -p 2345` and then use something like
|
4
|
+
# `curl -u admin:test http://localhost:2345/`.
|
5
|
+
#
|
6
|
+
# You can also use Thin. Just run it with `thin -R config.ru -p 2345 -DV start`.
|
7
|
+
#
|
5
8
|
|
6
9
|
require "rack/api"
|
7
10
|
|
data/lib/rack/api/controller.rb
CHANGED
@@ -228,7 +228,7 @@ module Rack
|
|
228
228
|
formatter_name = format.split("_").collect {|word| word[0,1].upcase + word[1,word.size].downcase}.join("")
|
229
229
|
|
230
230
|
if Rack::API::Formatter.const_defined?(formatter_name)
|
231
|
-
formatter = Rack::API::Formatter.const_get(formatter_name).new(response, params)
|
231
|
+
formatter = Rack::API::Formatter.const_get(formatter_name).new(response, env, params)
|
232
232
|
formatter.to_format
|
233
233
|
elsif response.respond_to?("to_#{format}")
|
234
234
|
response.__send__("to_#{format}")
|
@@ -4,11 +4,12 @@ module Rack
|
|
4
4
|
class Base
|
5
5
|
attr_accessor :object
|
6
6
|
attr_accessor :params
|
7
|
+
attr_accessor :env
|
7
8
|
|
8
9
|
class AbstractMethodError < StandardError; end
|
9
10
|
|
10
|
-
def initialize(object, params)
|
11
|
-
@object, @params = object, params
|
11
|
+
def initialize(object, env, params)
|
12
|
+
@object, @env, @params = object, env, params
|
12
13
|
end
|
13
14
|
|
14
15
|
def to_format
|
data/lib/rack/api/version.rb
CHANGED
@@ -144,4 +144,30 @@ describe Rack::API, "Format" do
|
|
144
144
|
last_response.body.should == "ZOMG! Fffuuu!"
|
145
145
|
end
|
146
146
|
end
|
147
|
+
|
148
|
+
context "formatter helper methods" do
|
149
|
+
it "sets params" do
|
150
|
+
Rack::API.app do
|
151
|
+
version :v2 do
|
152
|
+
respond_to :json
|
153
|
+
get("/") { params }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
get "/v2", :foo => "bar"
|
158
|
+
last_response.body.should == {foo: "bar"}.to_json
|
159
|
+
end
|
160
|
+
|
161
|
+
it "sets env" do
|
162
|
+
Rack::API.app do
|
163
|
+
version :v2 do
|
164
|
+
respond_to :json
|
165
|
+
get("/") { env }
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
get "/v2", :foo => "bar"
|
170
|
+
JSON.load(last_response.body)["REQUEST_METHOD"].should == "GET"
|
171
|
+
end
|
172
|
+
end
|
147
173
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement: &
|
16
|
+
requirement: &2269556480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2269556480
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rack-mount
|
27
|
-
requirement: &
|
27
|
+
requirement: &2269555880 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.6.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2269555880
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: activesupport
|
38
|
-
requirement: &
|
38
|
+
requirement: &2269554780 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 3.0.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2269554780
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &2269553440 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '2.6'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2269553440
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rack-test
|
60
|
-
requirement: &
|
60
|
+
requirement: &2269483040 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 0.5.7
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2269483040
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: redis
|
71
|
-
requirement: &
|
71
|
+
requirement: &2269482580 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: 2.2.0
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2269482580
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: rake
|
82
|
-
requirement: &
|
82
|
+
requirement: &2269481900 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ~>
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0.9'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2269481900
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: ruby-debug19
|
93
|
-
requirement: &
|
93
|
+
requirement: &2269481220 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,7 +98,7 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *2269481220
|
102
102
|
description: Create web app APIs that respond to one or more formats using an elegant
|
103
103
|
DSL.
|
104
104
|
email:
|
@@ -179,7 +179,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
179
179
|
version: '0'
|
180
180
|
segments:
|
181
181
|
- 0
|
182
|
-
hash:
|
182
|
+
hash: -629518363732307002
|
183
183
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
184
184
|
none: false
|
185
185
|
requirements:
|
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
188
188
|
version: '0'
|
189
189
|
segments:
|
190
190
|
- 0
|
191
|
-
hash:
|
191
|
+
hash: -629518363732307002
|
192
192
|
requirements: []
|
193
193
|
rubyforge_project:
|
194
194
|
rubygems_version: 1.8.6
|