rest_area 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f70d62f70a715f83edd40930f9fca00f4120718
4
+ data.tar.gz: 97a8e2cb5acd33a92d7d364013447e99cb11d6a8
5
+ SHA512:
6
+ metadata.gz: 7af06c764354110400947574c63c7dde3ab8570ca6fcb6240598789dab83fbd99c91261f7b4997467eaa84f215f8c0e1f9c68eca17bf58f64ca41f5eaee06f40
7
+ data.tar.gz: 2e287e1c13e57b24eb35c85b776b304ef9c7ac4c025fd5ab9b40c07d06946a137898db8cb824a9e8c3ec5ed8dcadb13e78023e28155d34c1ce2419092ca1193b
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = RestArea
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
6
+
7
+ begin
8
+ require 'bundler/setup'
9
+ rescue LoadError
10
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
11
+ end
12
+
13
+ begin
14
+ require 'rdoc/task'
15
+ rescue LoadError
16
+ require 'rdoc/rdoc'
17
+ require 'rake/rdoctask'
18
+ RDoc::Task = Rake::RDocTask
19
+ end
20
+
21
+ RDoc::Task.new(:rdoc) do |rdoc|
22
+ rdoc.rdoc_dir = 'rdoc'
23
+ rdoc.title = 'RestArea'
24
+ rdoc.options << '--line-numbers'
25
+ rdoc.rdoc_files.include('README.rdoc')
26
+ rdoc.rdoc_files.include('lib/**/*.rb')
27
+ end
28
+
29
+ Bundler::GemHelper.install_tasks
30
+
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ module RestArea
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,67 @@
1
+ module RestArea
2
+ class RestController < ApplicationController
3
+ skip_before_filter :verify_authenticity_token
4
+ before_filter :get_class
5
+
6
+ # GET
7
+ def index
8
+ render json:{ @roots => @klass.all(query_params) }.to_json(root:false)
9
+ end
10
+
11
+ def show
12
+ render json: @klass.find(params[:id]).to_json(:root => @root), :status => :ok
13
+ end
14
+ alias_method :edit, :show
15
+
16
+ # POST
17
+ def create
18
+ object = @klass.new(params[@root.to_sym])
19
+ if object.save
20
+ render json: object.to_json(:root => @root), :status => :created
21
+ else
22
+ render_errors(object)
23
+ end
24
+ end
25
+
26
+ # PUT
27
+ def update
28
+ object = @klass.find(params[:id])
29
+ if object.update_attributes(params[@root.to_sym])
30
+ render json: object.to_json(:root => @root), :status => :ok
31
+ else
32
+ render_errors(object)
33
+ end
34
+ end
35
+
36
+ # DELETE
37
+ def delete
38
+ object = @klass.find(params[:id])
39
+ if object.destroy
40
+ render json: object.to_json(:root => @root), :status => :ok
41
+ else
42
+ render_errors(object)
43
+ end
44
+ end
45
+
46
+ private
47
+
48
+ def render_errors(object)
49
+ render json: {errors: object.errors}, :status => :unprocessable_entity
50
+ end
51
+
52
+ def query_params
53
+ params.slice('limit','order').symbolize_keys
54
+ end
55
+
56
+ def get_class
57
+ @klass = params[:klass].singularize.camelize.constantize
58
+ unless [Thing].include? @klass
59
+ raise ActionController::RoutingError.new("Resource Does Not Exist")
60
+ end
61
+
62
+ @roots = ActionController::Base.helpers.sanitize(params[:klass])
63
+ @root = @roots.singularize
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,4 @@
1
+ module RestArea
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>RestArea</title>
5
+ <%= stylesheet_link_tag "rest_area/application", :media => "all" %>
6
+ <%= javascript_include_tag "rest_area/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ RestArea::Engine.routes.draw do
2
+ get '/:klass', :to => "rest#index"
3
+ get '/:klass/:id', :to => "rest#show"
4
+ post '/:klass', :to => "rest#create"
5
+ put '/:klass/:id', :to => "rest#update"
6
+ delete '/:klass/:id', :to => "rest#delete"
7
+ end
@@ -0,0 +1,5 @@
1
+ module RestArea
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace RestArea
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module RestArea
2
+ VERSION = "0.0.1"
3
+ end
data/lib/rest_area.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "rest_area/engine"
2
+
3
+ module RestArea
4
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :rest_area do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rest_area
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Benjamin Guest
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.17
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.17
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.0.0.beta
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.0.0.beta
41
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 1.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 1.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: combustion
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.5.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.5.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: RestArea adds a restfull controller and api to any Rails Application,
84
+ simply add the gem and whitelist of available models
85
+ email:
86
+ - benguest@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - MIT-LICENSE
92
+ - README.rdoc
93
+ - Rakefile
94
+ - app/assets/javascripts/rest_area/application.js
95
+ - app/assets/stylesheets/rest_area/application.css
96
+ - app/controllers/rest_area/application_controller.rb
97
+ - app/controllers/rest_area/rest_controller.rb
98
+ - app/helpers/rest_area/application_helper.rb
99
+ - app/views/layouts/rest_area/application.html.erb
100
+ - config/routes.rb
101
+ - lib/rest_area.rb
102
+ - lib/rest_area/engine.rb
103
+ - lib/rest_area/version.rb
104
+ - lib/tasks/rest_area_tasks.rake
105
+ homepage: https://github.com/bguest/rest_area
106
+ licenses: []
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.2.2
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Adds a restfull controller and api to a Rails Application
128
+ test_files: []