rest_area 0.0.1 → 1.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f70d62f70a715f83edd40930f9fca00f4120718
4
- data.tar.gz: 97a8e2cb5acd33a92d7d364013447e99cb11d6a8
3
+ metadata.gz: 072ac3365b0365f2606e8713e02a3af8124a80cd
4
+ data.tar.gz: fae9015327e25c0a0b939bb57a06b0ab97e796b3
5
5
  SHA512:
6
- metadata.gz: 7af06c764354110400947574c63c7dde3ab8570ca6fcb6240598789dab83fbd99c91261f7b4997467eaa84f215f8c0e1f9c68eca17bf58f64ca41f5eaee06f40
7
- data.tar.gz: 2e287e1c13e57b24eb35c85b776b304ef9c7ac4c025fd5ab9b40c07d06946a137898db8cb824a9e8c3ec5ed8dcadb13e78023e28155d34c1ce2419092ca1193b
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
- render json:{ @roots => @klass.all(query_params) }.to_json(root:false)
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]).to_json(:root => @root), :status => :ok
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.to_json(:root => @root), :status => :created
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.to_json(:root => @root), :status => :ok
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.to_json(:root => @root), :status => :ok
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 [Thing].include? @klass
72
+ unless RestArea.class_whitelist.include? @klass
59
73
  raise ActionController::RoutingError.new("Resource Does Not Exist")
60
74
  end
61
75
 
@@ -1,3 +1,3 @@
1
1
  module RestArea
2
- VERSION = "0.0.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/rest_area.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "rest_area/engine"
2
2
 
3
+
3
4
  module RestArea
5
+ mattr_accessor :class_whitelist
4
6
  end
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.1
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-24 00:00:00.000000000 Z
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.rdoc
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
@@ -1,3 +0,0 @@
1
- = RestArea
2
-
3
- This project rocks and uses MIT-LICENSE.