sinatra-rabbit 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sinatra/rabbit/base.rb +22 -11
- data/lib/sinatra/rabbit/features.rb +21 -4
- data/sinatra-rabbit.gemspec +1 -1
- metadata +4 -4
data/lib/sinatra/rabbit/base.rb
CHANGED
@@ -64,27 +64,27 @@ module Sinatra
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def self.configuration
|
67
|
-
|
67
|
+
Thread.current[:rabbit_configuration] ||= {}
|
68
68
|
end
|
69
69
|
|
70
70
|
def self.enable(property)
|
71
|
-
|
71
|
+
configuration[property] = true
|
72
72
|
end
|
73
73
|
|
74
74
|
def self.enabled?(property)
|
75
|
-
|
75
|
+
!configuration[property].nil? and configuration[property] == true
|
76
76
|
end
|
77
77
|
|
78
78
|
def self.disabled?(property)
|
79
|
-
|
79
|
+
!configuration[property].nil? and configuration[property] == false
|
80
80
|
end
|
81
81
|
|
82
82
|
def self.disable(property)
|
83
|
-
|
83
|
+
configuration[property] = false
|
84
84
|
end
|
85
85
|
|
86
86
|
def self.set(property, value)
|
87
|
-
|
87
|
+
configuration[property] = value
|
88
88
|
end
|
89
89
|
|
90
90
|
# Automatically register the DSL to Sinatra::Base if this
|
@@ -97,9 +97,7 @@ module Sinatra
|
|
97
97
|
# end
|
98
98
|
#
|
99
99
|
def self.included(base)
|
100
|
-
|
101
|
-
:root_path => '/'
|
102
|
-
}
|
100
|
+
configuration[:root_path] = '/'
|
103
101
|
base.register(DSL)
|
104
102
|
end
|
105
103
|
|
@@ -153,6 +151,10 @@ module Sinatra
|
|
153
151
|
base_class.features.select { |f| f.collection == collection_name }
|
154
152
|
end
|
155
153
|
|
154
|
+
def self.feature(name)
|
155
|
+
features.find { |f| f.name == name }
|
156
|
+
end
|
157
|
+
|
156
158
|
def self.with_id!(id)
|
157
159
|
@with_id = ":#{id}"
|
158
160
|
end
|
@@ -189,7 +191,7 @@ module Sinatra
|
|
189
191
|
end
|
190
192
|
|
191
193
|
# Create operation class
|
192
|
-
operation = operation_class(self, operation_name).generate(self, operation_name, &block)
|
194
|
+
operation = operation_class(self, operation_name).generate(self, operation_name, opts, &block)
|
193
195
|
@operations << operation
|
194
196
|
|
195
197
|
# Generate HEAD routes
|
@@ -244,9 +246,13 @@ module Sinatra
|
|
244
246
|
@method ||= method || BaseCollection.http_method_for(@name)
|
245
247
|
end
|
246
248
|
|
247
|
-
def self.generate(collection, name, &block)
|
249
|
+
def self.generate(collection, name, opts={}, &block)
|
248
250
|
@name, @params, @collection = name, [], collection
|
251
|
+
@options = opts
|
249
252
|
@collection.features.select { |f| f.operations.map { |o| o.name}.include?(@name) }.each do |feature|
|
253
|
+
if Sinatra::Rabbit.configuration[:check_features]
|
254
|
+
next unless Sinatra::Rabbit.configuration[:check_features].call(collection.collection_name, feature.name)
|
255
|
+
end
|
250
256
|
feature.operations.each do |o|
|
251
257
|
instance_eval(&o.params)
|
252
258
|
end
|
@@ -272,6 +278,11 @@ module Sinatra
|
|
272
278
|
|
273
279
|
def self.control(&block)
|
274
280
|
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
|
275
286
|
@control ||= Proc.new do
|
276
287
|
begin
|
277
288
|
Rabbit::Validator.validate!(params, params_def)
|
@@ -18,13 +18,16 @@ module Sinatra
|
|
18
18
|
module Rabbit
|
19
19
|
class Feature
|
20
20
|
attr_reader :name
|
21
|
+
attr_reader :description
|
21
22
|
attr_reader :collection
|
22
23
|
attr_reader :operations
|
24
|
+
attr_reader :constraints
|
23
25
|
|
24
26
|
def initialize(name, opts={}, &block)
|
25
27
|
@name = name
|
26
28
|
@operations = []
|
27
29
|
@collection = opts[:for]
|
30
|
+
@constraints = {}
|
28
31
|
raise "Each feature must define collection for which it will be valid using :for parameter" unless @collection
|
29
32
|
instance_eval(&block) if block_given?
|
30
33
|
end
|
@@ -34,6 +37,14 @@ module Sinatra
|
|
34
37
|
@operations.find { |o| o.name == name }
|
35
38
|
end
|
36
39
|
|
40
|
+
def description(s=nil)
|
41
|
+
@description ||= s
|
42
|
+
end
|
43
|
+
|
44
|
+
def constraint(name, value)
|
45
|
+
@constraints[name] = value
|
46
|
+
end
|
47
|
+
|
37
48
|
class Operation
|
38
49
|
attr_reader :name
|
39
50
|
attr_reader :params
|
@@ -49,14 +60,20 @@ module Sinatra
|
|
49
60
|
module Features
|
50
61
|
|
51
62
|
def features(&block)
|
52
|
-
|
63
|
+
@features ||= []
|
53
64
|
instance_eval(&block) if block_given?
|
54
|
-
|
65
|
+
@features
|
55
66
|
end
|
56
67
|
|
57
68
|
def feature(name, opts={}, &block)
|
58
|
-
|
59
|
-
|
69
|
+
feature = @features.find { |f| f.name == name }
|
70
|
+
return feature unless block_given?
|
71
|
+
if feature
|
72
|
+
feature.class_eval(&block)
|
73
|
+
else
|
74
|
+
@features << Feature.new(name, opts, &block) if block_given?
|
75
|
+
end
|
76
|
+
@features.find { |f| f.name == name }
|
60
77
|
end
|
61
78
|
|
62
79
|
def self.included(base)
|
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.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: 2012-04-
|
12
|
+
date: 2012-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
16
|
-
requirement: &
|
16
|
+
requirement: &70094500372800 !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: *70094500372800
|
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
|