blindgaenger-sinatra-rest 0.3.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +23 -25
- data/lib/sinatra/rest/adapters.rb +16 -3
- metadata +4 -3
data/README.textile
CHANGED
@@ -9,17 +9,17 @@ h2. Installation
|
|
9
9
|
|
10
10
|
Guess what!
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
sudo gem source --add http://gems.github.com
|
13
|
+
sudo gem install blindgaenger-sinatra-rest
|
14
14
|
|
15
15
|
|
16
16
|
h2. Usage
|
17
17
|
|
18
|
-
Of course you need to require the gem in your
|
18
|
+
Of course you need to require the gem in your Sinatra application:
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
require 'rubygems'
|
21
|
+
require 'sinatra'
|
22
|
+
require 'sinatra/rest'
|
23
23
|
|
24
24
|
It's very similar to defining routes in Sinatra (@get@, @post@, ...). But this
|
25
25
|
time you don't define the routes by yourself, but use the model's name for
|
@@ -28,8 +28,8 @@ convention.
|
|
28
28
|
For example, if the model's class is called @Person@ you only need to add this
|
29
29
|
line:
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
rest Person
|
32
|
+
|
33
33
|
Which will add the following RESTful routes to your application. (Note the
|
34
34
|
pluralization of @Person@ to the @/people/*@ routes.)
|
35
35
|
|
@@ -47,27 +47,25 @@ on your model, *appropriate routing and redirecting* and *named url helpers*.
|
|
47
47
|
For instance, you can imagine the following code to be added for the @/people@
|
48
48
|
and @/people/:id@ routes.
|
49
49
|
|
50
|
-
<pre>
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
rest Person, :renderer => :erb
|
50
|
+
<pre><code>
|
51
|
+
# simply add this line
|
52
|
+
|
53
|
+
rest Person, :renderer => :erb
|
55
54
|
|
56
|
-
|
55
|
+
# and this is generated for you
|
57
56
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
get '/people' do
|
58
|
+
@people = Person.all
|
59
|
+
erb :"people/index", options
|
60
|
+
end
|
62
61
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
62
|
+
put '/people/:id' do
|
63
|
+
@person = Person.find_by_id(params[:id])
|
64
|
+
redirect url_for_people_show(@person), 'person updated'
|
65
|
+
end
|
67
66
|
|
68
|
-
|
69
|
-
</code>
|
70
|
-
</pre>
|
67
|
+
# further restful routes for Person ...
|
68
|
+
</code></pre>
|
71
69
|
|
72
70
|
That's only half the truth! The routes are generated dynamically, so all
|
73
71
|
defaults can be overridden (the behaviour, after/before callbacks, used renderer,
|
@@ -3,6 +3,11 @@ module Stone
|
|
3
3
|
def find_by_id(id)
|
4
4
|
get(id)
|
5
5
|
end
|
6
|
+
|
7
|
+
def delete(id)
|
8
|
+
model = self.find_by_id(id)
|
9
|
+
model.destroy if model
|
10
|
+
end
|
6
11
|
end
|
7
12
|
end
|
8
13
|
|
@@ -11,14 +16,22 @@ module DataMapper
|
|
11
16
|
def find_by_id(id)
|
12
17
|
get(id)
|
13
18
|
end
|
19
|
+
|
20
|
+
def delete(id)
|
21
|
+
model = self.find_by_id(id)
|
22
|
+
model.destroy if model
|
23
|
+
end
|
14
24
|
end
|
15
25
|
end
|
16
26
|
|
17
27
|
module ActiveRecord
|
18
|
-
|
19
|
-
|
20
|
-
|
28
|
+
class Base
|
29
|
+
class << self
|
30
|
+
def find_by_id(id)
|
31
|
+
find(id)
|
32
|
+
end
|
21
33
|
end
|
22
34
|
end
|
23
35
|
end
|
24
36
|
|
37
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blindgaenger-sinatra-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- blindgaenger
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-09-25 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- test/views/people/show.haml
|
60
60
|
has_rdoc: "false"
|
61
61
|
homepage: http://github.com/blindgaenger/sinatra-rest
|
62
|
+
licenses:
|
62
63
|
post_install_message:
|
63
64
|
rdoc_options: []
|
64
65
|
|
@@ -79,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
80
|
requirements: []
|
80
81
|
|
81
82
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.
|
83
|
+
rubygems_version: 1.3.5
|
83
84
|
signing_key:
|
84
85
|
specification_version: 2
|
85
86
|
summary: Generates RESTful routes for the models of a Sinatra application (ActiveRecord, DataMapper, Stone)
|