rack-backend-api 0.0.1 → 0.0.2
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/README.md +9 -1
- data/lib/backend_api.rb +4 -2
- data/rack-backend-api.gemspec +1 -1
- data/test/db.rb +8 -0
- data/test/spec_backend_api.rb +11 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -80,6 +80,13 @@ Then if you need to delete the entry with ID 4:
|
|
80
80
|
|
81
81
|
DELETE /admin/blog_post/4
|
82
82
|
|
83
|
+
The API also understands a camelcased class name:
|
84
|
+
|
85
|
+
DELETE /admin/BlogPost/4
|
86
|
+
|
87
|
+
This is my fave personally, but unfortunately it seems that windows servers are case insensitive.
|
88
|
+
Which means that if you have one, you need to stick with the under_scored names.
|
89
|
+
|
83
90
|
To be honest, that is almost everything you need because the ORM adapter builds the forms
|
84
91
|
and therefore use the right action and method for POST and PUT requests.
|
85
92
|
|
@@ -188,13 +195,14 @@ THANX
|
|
188
195
|
|
189
196
|
I'd like to thank [Manveru](https://github.com/manveru), [Pistos](https://github.com/pistos) and many others on the #ramaze IRC channel for being friendly, helpful and obviously savy.
|
190
197
|
|
191
|
-
Also I'd like to thank [
|
198
|
+
Also I'd like to thank [Konstantin Haase](https://github.com/rkh) for the same reasons as he helped me many times on #rack issues,
|
192
199
|
and because [almost-sinatra](https://github.com/rkh/almost-sinatra) is just made with the 8 nicest lines of code to read.
|
193
200
|
|
194
201
|
CHANGE LOG
|
195
202
|
==========
|
196
203
|
|
197
204
|
0.0.1 First version
|
205
|
+
0.0.2 Accept CamelCased class names
|
198
206
|
|
199
207
|
COPYRIGHT
|
200
208
|
=========
|
data/lib/backend_api.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
class BackendAPI
|
2
|
-
VERSION = [0,0,
|
2
|
+
VERSION = [0,0,2]
|
3
3
|
WRAP = <<-EOT
|
4
4
|
<!doctype html>
|
5
5
|
<html>
|
@@ -88,7 +88,9 @@ class BackendAPI
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def camel_case(s)
|
91
|
-
s.
|
91
|
+
return if s.nil?
|
92
|
+
c = s[0]
|
93
|
+
c>=65&&c<=90 ? s : s.split('_').map{|e|e.capitalize}.join
|
92
94
|
end
|
93
95
|
|
94
96
|
def save_and_respond
|
data/rack-backend-api.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'rack-backend-api'
|
3
|
-
s.version = "0.0.
|
3
|
+
s.version = "0.0.2"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.summary = "A Rack middleware that provides a simple API for your Admin section"
|
6
6
|
s.description = "The purpose of this Rack Middleware is to provide an API that interfaces with database actions in order to build a CMS."
|
data/test/db.rb
CHANGED
@@ -40,6 +40,14 @@ class Pic < ::Sequel::Model
|
|
40
40
|
create_table unless table_exists?
|
41
41
|
end
|
42
42
|
|
43
|
+
class CamelCasedClass < ::Sequel::Model
|
44
|
+
set_schema do
|
45
|
+
primary_key :id
|
46
|
+
String :name
|
47
|
+
end
|
48
|
+
create_table unless table_exists?
|
49
|
+
end
|
50
|
+
|
43
51
|
Haiku.create( :title=>'Autumn', :body=>"Rust the ground\nFlush the branches\nReveal the trees" )
|
44
52
|
Haiku.create( :title=>'Winter', :body=>"There is snow\nIt covers you\nBut you are still the most beautiful" )
|
45
53
|
Haiku.create( :title=>'Spring', :body=>"No inspiration" )
|
data/test/spec_backend_api.rb
CHANGED
@@ -37,7 +37,17 @@ describe 'API Misc' do
|
|
37
37
|
res = req_lint(BackendAPI.new(dummy_app)).get('/_version')
|
38
38
|
res.status.should==200
|
39
39
|
res.body.should==BackendAPI::VERSION.join('.')
|
40
|
-
end
|
40
|
+
end
|
41
|
+
should "Accept CamelCased or under_scrored class names" do
|
42
|
+
# I prefer CamelCased as it only needs to be eval(ed)
|
43
|
+
# But people are used to under_scrored
|
44
|
+
# And also Windows servers are case insensitive
|
45
|
+
res1 = req_lint(BackendAPI.new).get('/CamelCasedClass')
|
46
|
+
res1.status.should==200
|
47
|
+
res2 = req_lint(BackendAPI.new).get('/camel_cased_class')
|
48
|
+
res2.status.should==200
|
49
|
+
res1.body.should==res2.body.gsub('camel_cased_class', 'CamelCasedClass')
|
50
|
+
end
|
41
51
|
end
|
42
52
|
|
43
53
|
describe 'API Post' do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-backend-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mickael Riga
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-07-19 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|