grape 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grape might be problematic. Click here for more details.
- data/.gitignore +1 -1
- data/.yardoc/checksums +13 -0
- data/.yardoc/objects/Grape.dat +0 -0
- data/.yardoc/objects/Grape/API.dat +0 -0
- data/.yardoc/objects/Grape/API/auth_c.dat +0 -0
- data/.yardoc/objects/Grape/API/build_endpoint_c.dat +0 -0
- data/.yardoc/objects/Grape/API/call_c.dat +0 -0
- data/.yardoc/objects/Grape/API/compile_path_c.dat +0 -0
- data/.yardoc/objects/Grape/API/default_format_c.dat +0 -0
- data/.yardoc/objects/Grape/API/delete_c.dat +0 -0
- data/.yardoc/objects/Grape/API/get_c.dat +0 -0
- data/.yardoc/objects/Grape/API/group_c.dat +0 -0
- data/.yardoc/objects/Grape/API/head_c.dat +0 -0
- data/.yardoc/objects/Grape/API/helpers_c.dat +0 -0
- data/.yardoc/objects/Grape/API/http_basic_c.dat +0 -0
- data/.yardoc/objects/Grape/API/inherited_c.dat +0 -0
- data/.yardoc/objects/Grape/API/logger_c.dat +0 -0
- data/.yardoc/objects/Grape/API/namespace_c.dat +0 -0
- data/.yardoc/objects/Grape/API/nest_c.dat +0 -0
- data/.yardoc/objects/Grape/API/post_c.dat +0 -0
- data/.yardoc/objects/Grape/API/prefix_c.dat +0 -0
- data/.yardoc/objects/Grape/API/put_c.dat +0 -0
- data/.yardoc/objects/Grape/API/reset_21_c.dat +0 -0
- data/.yardoc/objects/Grape/API/resource_c.dat +0 -0
- data/.yardoc/objects/Grape/API/resources_c.dat +0 -0
- data/.yardoc/objects/Grape/API/route_c.dat +0 -0
- data/.yardoc/objects/Grape/API/route_set_c.dat +0 -0
- data/.yardoc/objects/Grape/API/scope_c.dat +0 -0
- data/.yardoc/objects/Grape/API/set_c.dat +0 -0
- data/.yardoc/objects/Grape/API/settings_c.dat +0 -0
- data/.yardoc/objects/Grape/API/settings_stack_c.dat +0 -0
- data/.yardoc/objects/Grape/API/version_c.dat +0 -0
- data/.yardoc/objects/Grape/Endpoint.dat +0 -0
- data/.yardoc/objects/Grape/Endpoint/block_3D_c.dat +0 -0
- data/.yardoc/objects/Grape/Endpoint/block_c.dat +0 -0
- data/.yardoc/objects/Grape/Endpoint/call_c.dat +0 -0
- data/.yardoc/objects/Grape/Endpoint/call_i.dat +0 -0
- data/.yardoc/objects/Grape/Endpoint/env_i.dat +0 -0
- data/.yardoc/objects/Grape/Endpoint/error_21_i.dat +0 -0
- data/.yardoc/objects/Grape/Endpoint/generate_c.dat +0 -0
- data/.yardoc/objects/Grape/Endpoint/header_i.dat +0 -0
- data/.yardoc/objects/Grape/Endpoint/params_i.dat +0 -0
- data/.yardoc/objects/Grape/Endpoint/request_i.dat +0 -0
- data/.yardoc/objects/Grape/Endpoint/status_i.dat +0 -0
- data/.yardoc/objects/Grape/Endpoint/version_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Auth.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Auth/Basic.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Auth/Basic/authenticator_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Auth/Basic/basic_request_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Auth/Basic/before_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Auth/Basic/credentials_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Auth/Basic/initialize_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Auth/OAuth2.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Auth/OAuth2/before_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Auth/OAuth2/default_options_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Auth/OAuth2/error_out_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Auth/OAuth2/parse_authorization_header_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Auth/OAuth2/token_class_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Auth/OAuth2/verify_token_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Base.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Base/after_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Base/app_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Base/before_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Base/call_21_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Base/call_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Base/default_options_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Base/env_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Base/initialize_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Base/options_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Base/request_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Base/response_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Error.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Error/call_21_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Error/error_response_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Formatter.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Formatter/CONTENT_TYPES.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Formatter/after_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Formatter/before_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Formatter/content_types_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Formatter/default_options_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Formatter/encode_json_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Formatter/encode_txt_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Formatter/format_from_extension_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Formatter/format_from_header_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Formatter/headers_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Formatter/mime_array_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Formatter/mime_types_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Prefixer.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Prefixer/before_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Prefixer/prefix_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Versioner.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Versioner/before_i.dat +0 -0
- data/.yardoc/objects/Grape/Middleware/Versioner/default_options_i.dat +0 -0
- data/.yardoc/objects/Grape/MiddlewareStack.dat +0 -0
- data/.yardoc/objects/Grape/MiddlewareStack/initialize_i.dat +0 -0
- data/.yardoc/objects/Grape/MiddlewareStack/stack_i.dat +0 -0
- data/.yardoc/objects/Grape/MiddlewareStack/to_app_i.dat +0 -0
- data/.yardoc/objects/Grape/MiddlewareStack/use_i.dat +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/.yardoc/proxy_types +2 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +6 -0
- data/README.markdown +3 -3
- data/VERSION +1 -1
- data/grape.gemspec +108 -6
- data/lib/grape/api.rb +59 -21
- data/lib/grape/middleware/base.rb +1 -1
- data/lib/grape/middleware/error.rb +1 -1
- data/spec/grape/api_spec.rb +85 -4
- data/spec/grape/endpoint_spec.rb +13 -1
- data/spec/grape/middleware/auth/basic_spec.rb +2 -2
- metadata +161 -49
- data/lib/grape/middleware_stack.rb +0 -35
- data/spec/grape/middleware_stack_spec.rb +0 -47
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'grape'
|
2
|
-
|
3
|
-
module Grape
|
4
|
-
class MiddlewareStack
|
5
|
-
attr_reader :stack
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@stack = []
|
9
|
-
end
|
10
|
-
|
11
|
-
# Add a new middleware to the stack. Syntax
|
12
|
-
# is identical to normal middleware <tt>#use</tt>
|
13
|
-
# functionality.
|
14
|
-
#
|
15
|
-
# @param [Class] klass The middleware class.
|
16
|
-
def use(klass, *args)
|
17
|
-
if index = @stack.index(@stack.find{|a| a.first == klass})
|
18
|
-
@stack[index] = [klass, *args]
|
19
|
-
else
|
20
|
-
@stack << [klass, *args]
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# Apply this middleware stack to a
|
25
|
-
# Rack application.
|
26
|
-
def to_app(app)
|
27
|
-
b = Rack::Builder.new
|
28
|
-
for middleware in stack
|
29
|
-
b.use *middleware
|
30
|
-
end
|
31
|
-
b.run app
|
32
|
-
b.to_app
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Grape::MiddlewareStack do
|
4
|
-
subject { Grape::MiddlewareStack.new }
|
5
|
-
|
6
|
-
it 'should be able to add middlewares' do
|
7
|
-
subject.use Grape::Middleware::Error
|
8
|
-
subject.stack.first.should == [Grape::Middleware::Error]
|
9
|
-
end
|
10
|
-
|
11
|
-
context 'class uniqueness' do
|
12
|
-
it 'should not increase the stack size when doubling up on a use' do
|
13
|
-
2.times{ subject.use Grape::Middleware::Error }
|
14
|
-
subject.stack.size.should == 1
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should increase the stack size when a novel class is added' do
|
18
|
-
subject.use Grape::Middleware::Error
|
19
|
-
subject.use Grape::Middleware::Prefixer
|
20
|
-
subject.use Grape::Middleware::Error
|
21
|
-
subject.stack.should == [[Grape::Middleware::Error], [Grape::Middleware::Prefixer]]
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe '#run' do
|
26
|
-
class ExampleMiddleware
|
27
|
-
def initialize(app, say = 'what')
|
28
|
-
@app = app
|
29
|
-
@say = say
|
30
|
-
end
|
31
|
-
|
32
|
-
def call(env)
|
33
|
-
(env['say'] ||= []) << @say
|
34
|
-
@app.call(env)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
before do
|
39
|
-
subject.use ExampleMiddleware
|
40
|
-
subject.use ExampleMiddleware, 'yo'
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should call the middlewares in the stack' do
|
44
|
-
subject.to_app(lambda{|env| env['say'].should == ['yo']}).call({})
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|