rest_framework 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -3
- data/app/assets/images/rest_framework_favicon.ico +0 -0
- data/app/assets/javascripts/rest_framework.js +0 -0
- data/app/assets/stylesheets/rest_framework.css +3 -0
- data/app/views/layouts/rest_framework.html.erb +47 -0
- data/app/views/rest_framework/_routes.html.erb +18 -0
- data/app/views/rest_framework/default.html.erb +0 -0
- data/lib/rest_framework.rb +1 -0
- data/lib/rest_framework/VERSION_STAMP +1 -1
- data/lib/rest_framework/controllers/base.rb +35 -3
- data/lib/rest_framework/engine.rb +2 -0
- data/lib/rest_framework/routers.rb +2 -2
- metadata +9 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 117f77ddfdeadf0ae912fe3211d78135db7f72adbb55e8531dfc4766954455cc
|
4
|
+
data.tar.gz: 064f2f56125d4af20753e3a8d88eeea5e1617c58e492f1b8517ed04c2f58b730
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab6d2e0870adee08f98c0e7c89761ce59d5e5be9e051e0045b6b0c56625d1d09225ca34ac87223e2b3d41687fe9c35235514c5b2d0479f42ef576cc47d869c9d
|
7
|
+
data.tar.gz: f8f4c6e08d10cc7e7f7500412714835b67ac3aa234ecd619abba78677ea3d5055713dc12dc2993e6bce67a7b9bd10187f833b985173dcd4942f6c0e4bd417548
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# REST Framework
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/rest_framework.svg)](https://badge.fury.io/rb/rest_framework)
|
4
|
+
[![Build Status](https://travis-ci.org/gregschmit/rails-rest-framework.svg?branch=master)](https://travis-ci.org/gregschmit/rails-rest-framework)
|
5
|
+
|
3
6
|
REST Framework helps you build awesome APIs in Ruby on Rails.
|
4
7
|
|
5
8
|
**The Problem**: Building controllers for APIs usually involves writing a lot of redundant CRUD
|
@@ -65,13 +68,13 @@ end
|
|
65
68
|
```
|
66
69
|
|
67
70
|
Note that you can also override `get_model` and `get_recordset` instance methods to override the API
|
68
|
-
behavior
|
71
|
+
behavior dynamically per-request.
|
69
72
|
|
70
73
|
### Routing
|
71
74
|
|
72
75
|
You can use Rails' `resource`/`resources` routers to route your API, however if you want
|
73
|
-
`@extra_actions
|
74
|
-
`rest_resource
|
76
|
+
`@extra_actions` / `@extra_member_actions` to be routed automatically, then you can use the
|
77
|
+
`rest_resource` / `rest_resources` routers provided by this gem. You can also use `rest_root` to route
|
75
78
|
the root of your API:
|
76
79
|
|
77
80
|
```
|
Binary file
|
File without changes
|
@@ -0,0 +1,47 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title><%= @title %></title>
|
5
|
+
<meta charset="utf-8">
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
<%= csp_meta_tag %>
|
9
|
+
|
10
|
+
<%= favicon_link_tag 'rest_framework_favicon.ico' %>
|
11
|
+
|
12
|
+
<%= stylesheet_link_tag 'application', media: 'all' %>
|
13
|
+
<%= javascript_include_tag 'application' %>
|
14
|
+
<%= stylesheet_link_tag 'rest_framework', media: 'all' %>
|
15
|
+
<%= javascript_include_tag 'rest_framework' %>
|
16
|
+
</head>
|
17
|
+
|
18
|
+
<body>
|
19
|
+
<div class="bg-dark">
|
20
|
+
<div class="w-100 m-0 p-0" style="height: .3em; background-color: #a00;"></div>
|
21
|
+
<nav class="navbar navbar-dark bg-dark">
|
22
|
+
<div class="container">
|
23
|
+
<span class="navbar-brand p-0">
|
24
|
+
<h1 class="text-light font-weight-light m-0 p-0" style="font-size: 1em"><%= @template_logo_text %></h1>
|
25
|
+
</span>
|
26
|
+
</div>
|
27
|
+
</nav>
|
28
|
+
</div>
|
29
|
+
<div class="container py-3">
|
30
|
+
<div class="container">
|
31
|
+
<div class="row">
|
32
|
+
<h1><%= @title %></h1>
|
33
|
+
</div>
|
34
|
+
<div class="row">
|
35
|
+
<h2>Payload</h2><br>
|
36
|
+
<div><pre><%= JSON.pretty_generate(JSON.parse(@payload.to_json)) %></pre></div>
|
37
|
+
</div>
|
38
|
+
<% unless @routes.blank? %>
|
39
|
+
<div class="row">
|
40
|
+
<h2>Routes</h2>
|
41
|
+
<%= render partial: 'rest_framework/routes' %>
|
42
|
+
</div>
|
43
|
+
<% end %>
|
44
|
+
</div>
|
45
|
+
</div>
|
46
|
+
</body>
|
47
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<table class="table">
|
2
|
+
<thead>
|
3
|
+
<tr>
|
4
|
+
<th scope="col">Verb</th>
|
5
|
+
<th scope="col">Path</th>
|
6
|
+
<th scope="col">Action</th>
|
7
|
+
</tr>
|
8
|
+
</thead>
|
9
|
+
<tbody>
|
10
|
+
<% @routes.each do |r| %>
|
11
|
+
<tr>
|
12
|
+
<td><%= r[:verb] %></td>
|
13
|
+
<td><%= r[:path] %></td>
|
14
|
+
<td><%= r[:action] %></td>
|
15
|
+
</tr>
|
16
|
+
<% end %>
|
17
|
+
</tbody>
|
18
|
+
</table>
|
File without changes
|
data/lib/rest_framework.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -53,6 +53,7 @@ module RESTFramework
|
|
53
53
|
# end
|
54
54
|
|
55
55
|
_restframework_attr_reader(:extra_actions, default: {})
|
56
|
+
_restframework_attr_reader(:template_logo_text, default: 'Rails REST Framework')
|
56
57
|
|
57
58
|
def skip_actions(skip_undefined: true)
|
58
59
|
# first, skip explicitly skipped actions
|
@@ -73,11 +74,42 @@ module RESTFramework
|
|
73
74
|
base.extend ClassMethods
|
74
75
|
end
|
75
76
|
|
77
|
+
def _get_routes
|
78
|
+
begin
|
79
|
+
formatter = ActionDispatch::Routing::ConsoleFormatter::Sheet
|
80
|
+
rescue NameError
|
81
|
+
formatter = ActionDispatch::Routing::ConsoleFormatter
|
82
|
+
end
|
83
|
+
return ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes).format(
|
84
|
+
formatter.new
|
85
|
+
).lines[1..].map { |r| r.split.last(3) }.map { |r|
|
86
|
+
{verb: r[0], path: r[1], action: r[2]}
|
87
|
+
}.select { |r| r[:path].start_with?(request.path) }
|
88
|
+
end
|
89
|
+
|
76
90
|
# Helper alias for `respond_to`/`render`, and replace nil responses with blank ones.
|
77
|
-
def api_response(
|
91
|
+
def api_response(payload, html_kwargs: nil, json_kwargs: nil, **kwargs)
|
92
|
+
html_kwargs ||= {}
|
93
|
+
json_kwargs ||= {}
|
94
|
+
|
78
95
|
respond_to do |format|
|
79
|
-
format.html
|
80
|
-
|
96
|
+
format.html {
|
97
|
+
kwargs = kwargs.merge(html_kwargs)
|
98
|
+
@template_logo_text ||= "Rails REST Framework"
|
99
|
+
@title ||= self.controller_name.camelize
|
100
|
+
@routes ||= self._get_routes
|
101
|
+
@payload = payload
|
102
|
+
begin
|
103
|
+
render(**kwargs)
|
104
|
+
rescue ActionView::MissingTemplate # fallback to rest_framework default view
|
105
|
+
kwargs[:template] = "rest_framework/default"
|
106
|
+
end
|
107
|
+
render(**kwargs)
|
108
|
+
}
|
109
|
+
format.json {
|
110
|
+
kwargs = kwargs.merge(json_kwargs)
|
111
|
+
render(json: payload || '', **kwargs)
|
112
|
+
}
|
81
113
|
end
|
82
114
|
end
|
83
115
|
end
|
@@ -25,10 +25,10 @@ module ActionDispatch::Routing
|
|
25
25
|
|
26
26
|
# convert class name to class
|
27
27
|
begin
|
28
|
-
controller = mod.const_get(name
|
28
|
+
controller = mod.const_get(name)
|
29
29
|
rescue NameError
|
30
30
|
if fallback_reverse_pluralization
|
31
|
-
controller = mod.const_get(name_reverse
|
31
|
+
controller = mod.const_get(name_reverse)
|
32
32
|
else
|
33
33
|
raise
|
34
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rest_framework
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory N. Schmit
|
@@ -33,11 +33,18 @@ extra_rdoc_files: []
|
|
33
33
|
files:
|
34
34
|
- LICENSE
|
35
35
|
- README.md
|
36
|
+
- app/assets/images/rest_framework_favicon.ico
|
37
|
+
- app/assets/javascripts/rest_framework.js
|
38
|
+
- app/assets/stylesheets/rest_framework.css
|
39
|
+
- app/views/layouts/rest_framework.html.erb
|
40
|
+
- app/views/rest_framework/_routes.html.erb
|
41
|
+
- app/views/rest_framework/default.html.erb
|
36
42
|
- lib/rest_framework.rb
|
37
43
|
- lib/rest_framework/VERSION_STAMP
|
38
44
|
- lib/rest_framework/controllers.rb
|
39
45
|
- lib/rest_framework/controllers/base.rb
|
40
46
|
- lib/rest_framework/controllers/models.rb
|
47
|
+
- lib/rest_framework/engine.rb
|
41
48
|
- lib/rest_framework/routers.rb
|
42
49
|
- lib/rest_framework/version.rb
|
43
50
|
homepage: https://github.com/gregschmit/rails-rest-framework
|
@@ -50,6 +57,7 @@ post_install_message:
|
|
50
57
|
rdoc_options: []
|
51
58
|
require_paths:
|
52
59
|
- lib
|
60
|
+
- app
|
53
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
54
62
|
requirements:
|
55
63
|
- - ">="
|