sinatra-rabbit 1.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://secure.travis-ci.org/mifo/sinatra-rabbit.png?branch=master)](http://travis-ci.org/mifo/sinatra-rabbit)
2
+
1
3
  Sinatra::Rabbit
2
4
  =============
3
5
 
@@ -17,6 +19,9 @@ as well as in Deltacloud.
17
19
 
18
20
  Full documentation: [rubydoc.info/github/mifo/sinatra-rabbit](http://rubydoc.info/github/mifo/sinatra-rabbit/master)
19
21
 
22
+ An example application (modular Deltacloud API) can be found here:
23
+ [github.com/mifo/deltacloud-modular](https://github.com/mifo/deltacloud-modular)
24
+
20
25
  Features
21
26
  -------
22
27
 
@@ -32,10 +32,31 @@ module Sinatra
32
32
  module Rabbit
33
33
 
34
34
  STANDARD_OPERATIONS = {
35
- :create => { :member => false, :method => :post, :collection => true },
36
- :show => { :member => false, :method => :get },
37
- :destroy => { :member => false, :method => :delete },
38
- :index => { :member => false, :method => :get, :collection => true }
35
+ :create => {
36
+ :member => false,
37
+ :method => :post,
38
+ :collection => true
39
+ },
40
+ :show => {
41
+ :member => false,
42
+ :method => :get,
43
+ :required_params => [ :id ]
44
+ },
45
+ :destroy => {
46
+ :member => false,
47
+ :method => :delete,
48
+ :required_params => [ :id ]
49
+ },
50
+ :index => {
51
+ :member => false,
52
+ :method => :get,
53
+ :collection => true
54
+ },
55
+ :update => {
56
+ :member => false,
57
+ :method => :patch,
58
+ :required_params => [ :id ]
59
+ }
39
60
  }
40
61
 
41
62
  def self.configure(&block)
@@ -156,6 +177,7 @@ module Sinatra
156
177
  Rabbit::Documentation.for_collection(self, operations)
157
178
  end
158
179
 
180
+
159
181
  def self.operation(operation_name, opts={}, &block)
160
182
  @operations ||= []
161
183
  # Return operation when no block is given
@@ -167,7 +189,8 @@ module Sinatra
167
189
  end
168
190
 
169
191
  # Create operation class
170
- @operations << (operation = operation_class(self, operation_name).generate(self, operation_name, &block))
192
+ operation = operation_class(self, operation_name).generate(self, operation_name, &block)
193
+ @operations << operation
171
194
 
172
195
  # Generate HEAD routes
173
196
  unless Rabbit.disabled? :head_routes
@@ -187,8 +210,13 @@ module Sinatra
187
210
  # Make the full_path method on operation return currect operation path
188
211
  operation.set_route(root_path + route_for(path, operation_name, :id_name => @with_id || ':id'))
189
212
 
213
+ # Change the HTTP method to POST automatically for 'action' operations
214
+ if opts[:http_method]
215
+ operation.http_method(opts.delete(:http_method))
216
+ end
217
+
190
218
  # Define Sinatra::Base route
191
- base_class.send(http_method_for(operation_name), operation.full_path, opts, &operation.control)
219
+ base_class.send(operation.http_method || http_method_for(operation_name), operation.full_path, opts, &operation.control)
192
220
 
193
221
  # Generate OPTIONS routes
194
222
  unless Rabbit.disabled? :options_routes
@@ -199,6 +227,11 @@ module Sinatra
199
227
  self
200
228
  end
201
229
 
230
+ def self.action(action_name, opts={}, &block)
231
+ opts.merge!(:http_method => :post)
232
+ operation(action_name, opts, &block)
233
+ end
234
+
202
235
  def self.operations; @operations; end
203
236
 
204
237
  class Operation
@@ -207,6 +240,10 @@ module Sinatra
207
240
  @operation_path = path
208
241
  end
209
242
 
243
+ def self.http_method(method=nil)
244
+ @method ||= method || BaseCollection.http_method_for(@name)
245
+ end
246
+
210
247
  def self.generate(collection, name, &block)
211
248
  @name, @params, @collection = name, [], collection
212
249
  @collection.features.select { |f| f.operations.map { |o| o.name}.include?(@name) }.each do |feature|
@@ -214,7 +251,14 @@ module Sinatra
214
251
  instance_eval(&o.params)
215
252
  end
216
253
  end
254
+ if Sinatra::Rabbit::STANDARD_OPERATIONS.has_key? name
255
+ required_params = Sinatra::Rabbit::STANDARD_OPERATIONS[name][:required_params]
256
+ required_params.each do |p|
257
+ param p, :required, :string, "The #{p} parameter"
258
+ end unless required_params.nil?
259
+ end
217
260
  class_eval(&block)
261
+ description "#{name.to_s.capitalize} operation on #{@collection.name} collection" if description.nil?
218
262
  self
219
263
  end
220
264
 
@@ -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'
32
+ s.version = '1.0.1'
33
33
  s.date = Time.now
34
34
  s.summary = %q{Sinatra REST API DSL}
35
35
  s.files = FileList[
metadata CHANGED
@@ -1,46 +1,35 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sinatra-rabbit
3
- version: !ruby/object:Gem::Version
4
- hash: 15
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- version: "1.0"
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - The Apache Software Foundation
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2012-03-14 00:00:00 Z
18
- dependencies:
19
- - !ruby/object:Gem::Dependency
12
+ date: 2012-04-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
20
15
  name: sinatra
21
- prerelease: false
22
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70156043073960 !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 27
28
- segments:
29
- - 1
30
- - 3
31
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
32
21
  version: 1.3.0
33
22
  type: :runtime
34
- version_requirements: *id001
35
- description: " Rabbit is a Sinatra extension which can help you writing\n a simple REST API using easy to undestand DSL.\n"
23
+ prerelease: false
24
+ version_requirements: *70156043073960
25
+ description: ! " Rabbit is a Sinatra extension which can help you writing\n a
26
+ simple REST API using easy to undestand DSL.\n"
36
27
  email: dev@deltacloud.apache.org
37
28
  executables: []
38
-
39
29
  extensions: []
40
-
41
- extra_rdoc_files:
30
+ extra_rdoc_files:
42
31
  - LICENSE
43
- files:
32
+ files:
44
33
  - lib/sinatra/rabbit.rb
45
34
  - lib/sinatra/rabbit/base.rb
46
35
  - lib/sinatra/rabbit/base_collection.rb
@@ -53,38 +42,26 @@ files:
53
42
  - sinatra-rabbit.gemspec
54
43
  homepage: http://github.com/mifo/sinatra-rabbit
55
44
  licenses: []
56
-
57
45
  post_install_message:
58
46
  rdoc_options: []
59
-
60
- require_paths:
47
+ require_paths:
61
48
  - lib
62
- required_ruby_version: !ruby/object:Gem::Requirement
49
+ required_ruby_version: !ruby/object:Gem::Requirement
63
50
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- hash: 53
68
- segments:
69
- - 1
70
- - 8
71
- - 1
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
72
54
  version: 1.8.1
73
- required_rubygems_version: !ruby/object:Gem::Requirement
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
56
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- hash: 3
79
- segments:
80
- - 0
81
- version: "0"
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
82
61
  requirements: []
83
-
84
62
  rubyforge_project:
85
- rubygems_version: 1.8.10
63
+ rubygems_version: 1.8.15
86
64
  signing_key:
87
65
  specification_version: 3
88
66
  summary: Sinatra REST API DSL
89
67
  test_files: []
90
-