api_scaffold 0.2.0 → 0.2.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 +4 -4
- data/README.md +7 -2
- data/lib/api_scaffold/version.rb +1 -1
- data/lib/generators/api_scaffold/generator_helpers.rb +0 -8
- data/lib/generators/api_scaffold/templates/controllers/controller.rb +5 -22
- data/lib/generators/api_scaffold/templates/controllers/serializer_controller.rb +5 -20
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 837e66eb2af89f787a9e86612f616061d661cf6e32a44e0abc73481c6b90e921
|
4
|
+
data.tar.gz: '0393d39076b3cc3390d8a9bd5d80c48861133c5b0e5bbdb1741f92dfced9c787'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 630c5fe1f9c1c83b90fa5d09445dc9992aa8fffb6bc2a91b339d09840710362452955064934e827f6835bdb6ae62406e930f8e4ac3bc8def3153d4b22a6f36d5
|
7
|
+
data.tar.gz: 3ed60f893e21de1d93cb6f91abd0b546916eae373e11a9e5c2ec8ef12c5c2b197f4347ec9d27e1c7ee41fc395496c8f0d6314e6218db343ce83fccc9f43699ad
|
data/README.md
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
# ApiScaffold
|
2
2
|
|
3
|
-
A useful Rails API generator for scaffolding.
|
3
|
+
A useful Rails API generator for scaffolding that follows the jsonapi.org specification (http://jsonapi.org/). Works with :
|
4
4
|
- Fast JSON API/Active Model Serializers
|
5
5
|
- Rspec/TestUnit
|
6
6
|
- Fixtures/FactoryBot
|
7
7
|
- Api Pagination
|
8
|
-
- Apipie
|
9
8
|
|
9
|
+
For example if you have :
|
10
|
+
- Fast JSON API/AMS in your gemfile ? the scaffold will create a serializer and generate a controller using the scaffolded serializer.
|
11
|
+
- Rspec as your configured test framework ? the scaffold will generate rspec working controller tests
|
12
|
+
- Apipie installed ? the scaffold will generate api documentation
|
13
|
+
- api-pagination in your gemfile ? the scaffold will paginate the index method of scaffolded controller
|
10
14
|
## Installation
|
11
15
|
|
12
16
|
Add this line to your application's Gemfile:
|
@@ -44,6 +48,7 @@ If you wish to specify the api version:
|
|
44
48
|
|
45
49
|
## TODO
|
46
50
|
- Nested resources
|
51
|
+
- GraphQL
|
47
52
|
|
48
53
|
## Contributing
|
49
54
|
|
data/lib/api_scaffold/version.rb
CHANGED
@@ -22,10 +22,6 @@ module ApiScaffold
|
|
22
22
|
Gem::Specification::find_all_by_name(gem_name).any?
|
23
23
|
end
|
24
24
|
|
25
|
-
def apipie_installed?
|
26
|
-
File.exists? File.join(destination_root, "config/initializers/apipie.rb")
|
27
|
-
end
|
28
|
-
|
29
25
|
def error_serializer_created?
|
30
26
|
File.exists? File.join(destination_root, "app/serializers/error_serializer.rb")
|
31
27
|
end
|
@@ -61,10 +57,6 @@ module ApiScaffold
|
|
61
57
|
end
|
62
58
|
end.sort.to_h
|
63
59
|
end
|
64
|
-
|
65
|
-
def apipie_param(attribute_name)
|
66
|
-
"param :#{attribute_name}, String, 'TODO: #{attribute_name} descrption'"
|
67
|
-
end
|
68
60
|
end
|
69
61
|
end
|
70
62
|
end
|
@@ -6,30 +6,16 @@ require_dependency "<%= namespaced_path %>/application_controller"
|
|
6
6
|
class <%= prefixed_controller_class_name %>Controller < ApplicationController
|
7
7
|
before_action :set_<%= singular_table_name %>, only: [:show, :update, :destroy]
|
8
8
|
|
9
|
-
|
10
|
-
param :<%= singular_table_name %>, Hash, required: true, action_aware: true do
|
11
|
-
<% attributes_names.each do |attribute_name| -%><%= indent(apipie_param(attribute_name), 2) %>
|
12
|
-
<% end -%>end
|
13
|
-
end
|
14
|
-
|
15
|
-
api :GET, '/<%= plural_table_name %>', 'List <%= plural_table_name %>'
|
16
|
-
<% if gem_available?('api-pagination') %>param :page, String, 'Paginate results'
|
17
|
-
param :per_page, String, 'Number of records per page'
|
18
|
-
<% end -%>
|
19
|
-
<% end -%>def index
|
9
|
+
def index
|
20
10
|
@<%= plural_table_name %> = <%= 'paginate ' if gem_available?('api-pagination') %><%= orm_class.all(class_name) %>
|
21
11
|
render json: <%= "@#{plural_table_name}" %>
|
22
12
|
end
|
23
|
-
|
24
13
|
|
25
|
-
|
26
|
-
<% end -%>def show
|
14
|
+
def show
|
27
15
|
render json: <%= "@#{singular_table_name}" %>
|
28
16
|
end
|
29
17
|
|
30
|
-
|
31
|
-
param_group :<%= singular_table_name %>
|
32
|
-
<% end -%>def create
|
18
|
+
def create
|
33
19
|
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
|
34
20
|
|
35
21
|
if @<%= orm_instance.save %>
|
@@ -39,9 +25,7 @@ class <%= prefixed_controller_class_name %>Controller < ApplicationController
|
|
39
25
|
end
|
40
26
|
end
|
41
27
|
|
42
|
-
|
43
|
-
param_group :<%= singular_table_name %>
|
44
|
-
<% end -%>def update
|
28
|
+
def update
|
45
29
|
if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
46
30
|
render json: <%= "@#{singular_table_name}" %>
|
47
31
|
else
|
@@ -49,8 +33,7 @@ class <%= prefixed_controller_class_name %>Controller < ApplicationController
|
|
49
33
|
end
|
50
34
|
end
|
51
35
|
|
52
|
-
|
53
|
-
<% end -%>def destroy
|
36
|
+
def destroy
|
54
37
|
@<%= orm_instance.destroy %>
|
55
38
|
end
|
56
39
|
|
@@ -6,28 +6,16 @@ require_dependency "<%= namespaced_path %>/application_controller"
|
|
6
6
|
class <%= prefixed_controller_class_name %>Controller < ApplicationController
|
7
7
|
before_action :set_<%= singular_table_name %>, only: [:show, :update, :destroy]
|
8
8
|
|
9
|
-
|
10
|
-
param :<%= singular_table_name %>, Hash, required: true, action_aware: true do
|
11
|
-
<% attributes_names.each do |attribute_name| -%><%= indent(apipie_param(attribute_name), 2) %>
|
12
|
-
<% end -%>end
|
13
|
-
end
|
14
|
-
|
15
|
-
api :GET, '/<%= [prefix, plural_table_name].join("/") %>', 'List <%= plural_table_name %>'
|
16
|
-
<% if gem_available?('api-pagination') %>param :page, String, 'Paginate results'
|
17
|
-
param :per_page, String, 'Number of records per page'
|
18
|
-
<% end -%><% end -%>def index
|
9
|
+
def index
|
19
10
|
@<%= plural_table_name %> = <%= 'paginate ' if gem_available?('api-pagination') %><%= orm_class.all(class_name) %>
|
20
11
|
render json: <%= class_name %>Serializer.new(<%= "@#{plural_table_name}" %>)
|
21
12
|
end
|
22
13
|
|
23
|
-
|
24
|
-
<% end -%>def show
|
14
|
+
def show
|
25
15
|
render json: <%= class_name %>Serializer.new(<%= "@#{singular_table_name}" %>)
|
26
16
|
end
|
27
17
|
|
28
|
-
|
29
|
-
param_group :<%= singular_table_name %>
|
30
|
-
<% end -%>def create
|
18
|
+
def create
|
31
19
|
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
|
32
20
|
|
33
21
|
if @<%= orm_instance.save %>
|
@@ -37,9 +25,7 @@ class <%= prefixed_controller_class_name %>Controller < ApplicationController
|
|
37
25
|
end
|
38
26
|
end
|
39
27
|
|
40
|
-
|
41
|
-
param_group :<%= singular_table_name %>
|
42
|
-
<% end -%>def update
|
28
|
+
def update
|
43
29
|
if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
44
30
|
render json: <%= class_name %>Serializer.new(<%= "@#{singular_table_name}" %>)
|
45
31
|
else
|
@@ -47,8 +33,7 @@ class <%= prefixed_controller_class_name %>Controller < ApplicationController
|
|
47
33
|
end
|
48
34
|
end
|
49
35
|
|
50
|
-
|
51
|
-
<% end -%>def destroy
|
36
|
+
def destroy
|
52
37
|
@<%= orm_instance.destroy %>
|
53
38
|
end
|
54
39
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_scaffold
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Atkinson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|