sinatra-rabbit 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -218,7 +218,9 @@ module Sinatra
218
218
  end
219
219
 
220
220
  # Define Sinatra::Base route
221
- base_class.send(operation.http_method || http_method_for(operation_name), operation.full_path, opts, &operation.control)
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 Sinatra::Rabbit.configuration[:check_capability] and @options.has_key?(:with_capability)
282
- unless Sinatra::Rabbit.configuration[:check_capability].call(@options.delete(:with_capability))
283
- @control = Proc.new { [412, {}, "Required capability is missing for current resource and configuration"] }
284
- end
285
- end
286
- @control ||= Proc.new do
287
- begin
288
- Rabbit::Validator.validate!(params, params_def)
289
- rescue => e
290
- if e.kind_of? Rabbit::Validator::ValidationError
291
- halt e.http_status_code, e.message
292
- else
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
 
@@ -60,8 +60,9 @@ module Sinatra
60
60
  module Features
61
61
 
62
62
  def features(&block)
63
+ return @features || [] unless block_given?
63
64
  @features ||= []
64
- instance_eval(&block) if block_given?
65
+ instance_eval(&block)
65
66
  @features
66
67
  end
67
68
 
@@ -29,7 +29,7 @@ Gem::Specification.new do |s|
29
29
  a simple REST API using easy to undestand DSL.
30
30
  EOF
31
31
 
32
- s.version = '1.0.2'
32
+ s.version = '1.0.3'
33
33
  s.date = Time.now
34
34
  s.summary = %q{Sinatra REST API DSL}
35
35
  s.files = FileList[
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.2
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-03 00:00:00.000000000 Z
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: &70094500372800 !ruby/object:Gem::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: *70094500372800
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