sinatra-rabbit 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/sinatra/rabbit/base.rb +27 -16
- data/lib/sinatra/rabbit/features.rb +2 -1
- data/sinatra-rabbit.gemspec +1 -1
- metadata +4 -4
data/lib/sinatra/rabbit/base.rb
CHANGED
@@ -218,7 +218,9 @@ module Sinatra
|
|
218
218
|
end
|
219
219
|
|
220
220
|
# Define Sinatra::Base route
|
221
|
-
|
221
|
+
route_options = opts.clone
|
222
|
+
route_options.delete :with_capability
|
223
|
+
base_class.send(operation.http_method || http_method_for(operation_name), operation.full_path, route_options, &operation.control)
|
222
224
|
|
223
225
|
# Generate OPTIONS routes
|
224
226
|
unless Rabbit.disabled? :options_routes
|
@@ -230,7 +232,7 @@ module Sinatra
|
|
230
232
|
end
|
231
233
|
|
232
234
|
def self.action(action_name, opts={}, &block)
|
233
|
-
opts.merge!(:http_method => :post)
|
235
|
+
opts.merge!(:http_method => :post) unless opts[:http_method]
|
234
236
|
operation(action_name, opts, &block)
|
235
237
|
end
|
236
238
|
|
@@ -249,6 +251,7 @@ module Sinatra
|
|
249
251
|
def self.generate(collection, name, opts={}, &block)
|
250
252
|
@name, @params, @collection = name, [], collection
|
251
253
|
@options = opts
|
254
|
+
http_method(@options.delete(:http_method)) if @options.has_key? :http_method
|
252
255
|
@collection.features.select { |f| f.operations.map { |o| o.name}.include?(@name) }.each do |feature|
|
253
256
|
if Sinatra::Rabbit.configuration[:check_features]
|
254
257
|
next unless Sinatra::Rabbit.configuration[:check_features].call(collection.collection_name, feature.name)
|
@@ -271,6 +274,15 @@ module Sinatra
|
|
271
274
|
def self.full_path; @operation_path; end
|
272
275
|
def self.operation_name; @name; end
|
273
276
|
|
277
|
+
def self.has_capability?
|
278
|
+
@capability ||= Sinatra::Rabbit.configuration[:check_capability]
|
279
|
+
if @capability and @options.has_key?(:with_capability)
|
280
|
+
@capability.call(@options[:with_capability])
|
281
|
+
else
|
282
|
+
true
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
274
286
|
def self.description(text=nil)
|
275
287
|
return @description if text.nil?
|
276
288
|
@description = text
|
@@ -278,22 +290,21 @@ module Sinatra
|
|
278
290
|
|
279
291
|
def self.control(&block)
|
280
292
|
params_def = @params
|
281
|
-
if
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
raise e
|
293
|
+
if not has_capability?
|
294
|
+
@control = Proc.new { [412, {}, "The required capability to execute this operation is missing"] }
|
295
|
+
else
|
296
|
+
@control ||= Proc.new do
|
297
|
+
begin
|
298
|
+
Rabbit::Validator.validate!(params, params_def)
|
299
|
+
rescue => e
|
300
|
+
if e.kind_of? Rabbit::Validator::ValidationError
|
301
|
+
halt e.http_status_code, e.message
|
302
|
+
else
|
303
|
+
raise e
|
304
|
+
end
|
294
305
|
end
|
306
|
+
instance_eval(&block)
|
295
307
|
end
|
296
|
-
instance_eval(&block)
|
297
308
|
end
|
298
309
|
end
|
299
310
|
|
data/sinatra-rabbit.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-rabbit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
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: 2012-04-
|
12
|
+
date: 2012-04-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
16
|
-
requirement: &
|
16
|
+
requirement: &70288446299200 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: 1.3.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70288446299200
|
25
25
|
description: ! " Rabbit is a Sinatra extension which can help you writing\n a
|
26
26
|
simple REST API using easy to undestand DSL.\n"
|
27
27
|
email: dev@deltacloud.apache.org
|