rest_area 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/app/controllers/rest_area/rest_controller.rb +21 -7
- data/lib/rest_area/version.rb +1 -1
- data/lib/rest_area.rb +2 -0
- metadata +5 -5
- data/README.rdoc +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 072ac3365b0365f2606e8713e02a3af8124a80cd
|
4
|
+
data.tar.gz: fae9015327e25c0a0b939bb57a06b0ab97e796b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84e4e4a7e23661f4d24ae3bbc22d580aa44c9b2047ae0c2a4060c0a13451c33373f5238425c614649e5026c03c5fb29aa582bd0460a05ed3c7e68793d19b2e86
|
7
|
+
data.tar.gz: 46b397192acede9d404f9805e255a88058b391fb300a3f245f3deb7401af3484c9e67c8c2d273a1987c392a92bd2cd2bd52d3d14e8672ec7780db5f6e6fc8690
|
data/README.md
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# RestArea
|
2
|
+
|
3
|
+
This gem adds a off bare bones rest api to a rails application. Simply
|
4
|
+
create the initilizers file with the classes that you want to be in the
|
5
|
+
rest api and you will get the get basic rest routes for that class
|
6
|
+
This project rocks and uses MIT-LICENSE.
|
7
|
+
|
8
|
+
## Initilization
|
9
|
+
|
10
|
+
1. Create a file called rest_area.rb in your initilizers file
|
11
|
+
2. Add something the following in that file.
|
12
|
+
|
13
|
+
RestArea.class_whitelist = [YourModel, ThatYouWant, ToBeInYour, RestApi]
|
14
|
+
|
15
|
+
3. Add something like the following to your routes file.
|
16
|
+
|
17
|
+
mount RestArea::Engine => "/your_base_route"
|
18
|
+
|
@@ -1,15 +1,19 @@
|
|
1
1
|
module RestArea
|
2
2
|
class RestController < ApplicationController
|
3
3
|
skip_before_filter :verify_authenticity_token
|
4
|
-
before_filter :get_class
|
4
|
+
before_filter :get_class, :set_class_serializer
|
5
5
|
|
6
6
|
# GET
|
7
7
|
def index
|
8
|
-
|
8
|
+
if @serializer
|
9
|
+
render json: @klass.all, each_serializer: @serializer, root:@roots
|
10
|
+
else
|
11
|
+
render json:{ @roots => @klass.all }.to_json(root:false)
|
12
|
+
end
|
9
13
|
end
|
10
14
|
|
11
15
|
def show
|
12
|
-
render json: @klass.find(params[:id])
|
16
|
+
render json: @klass.find(params[:id]), root: @root
|
13
17
|
end
|
14
18
|
alias_method :edit, :show
|
15
19
|
|
@@ -17,7 +21,7 @@ module RestArea
|
|
17
21
|
def create
|
18
22
|
object = @klass.new(params[@root.to_sym])
|
19
23
|
if object.save
|
20
|
-
render json: object
|
24
|
+
render json: object, root:@root
|
21
25
|
else
|
22
26
|
render_errors(object)
|
23
27
|
end
|
@@ -27,7 +31,7 @@ module RestArea
|
|
27
31
|
def update
|
28
32
|
object = @klass.find(params[:id])
|
29
33
|
if object.update_attributes(params[@root.to_sym])
|
30
|
-
render json: object
|
34
|
+
render json: object, root:@root
|
31
35
|
else
|
32
36
|
render_errors(object)
|
33
37
|
end
|
@@ -37,7 +41,7 @@ module RestArea
|
|
37
41
|
def delete
|
38
42
|
object = @klass.find(params[:id])
|
39
43
|
if object.destroy
|
40
|
-
render json: object
|
44
|
+
render json: object, root:@root
|
41
45
|
else
|
42
46
|
render_errors(object)
|
43
47
|
end
|
@@ -53,9 +57,19 @@ module RestArea
|
|
53
57
|
params.slice('limit','order').symbolize_keys
|
54
58
|
end
|
55
59
|
|
60
|
+
def set_class_serializer
|
61
|
+
@serializer = ( '::' + @klass.to_s + "Serializer" ).constantize
|
62
|
+
rescue NameError => e
|
63
|
+
if e.message =~ /uninitialized constant/
|
64
|
+
@serializer = false
|
65
|
+
else
|
66
|
+
throw e
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
56
70
|
def get_class
|
57
71
|
@klass = params[:klass].singularize.camelize.constantize
|
58
|
-
unless
|
72
|
+
unless RestArea.class_whitelist.include? @klass
|
59
73
|
raise ActionController::RoutingError.new("Resource Does Not Exist")
|
60
74
|
end
|
61
75
|
|
data/lib/rest_area/version.rb
CHANGED
data/lib/rest_area.rb
CHANGED
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_area
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Guest
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.2.17
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.2.17
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -89,7 +89,7 @@ extensions: []
|
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
91
|
- MIT-LICENSE
|
92
|
-
- README.
|
92
|
+
- README.md
|
93
93
|
- Rakefile
|
94
94
|
- app/assets/javascripts/rest_area/application.js
|
95
95
|
- app/assets/stylesheets/rest_area/application.css
|
data/README.rdoc
DELETED