api_scaffold 0.1.6 → 0.1.7
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 +1 -1
- data/lib/api_scaffold/version.rb +1 -1
- data/lib/generators/api_scaffold/generator_helpers.rb +9 -0
- data/lib/generators/api_scaffold/templates/controllers/controller.rb +18 -3
- data/lib/generators/api_scaffold/templates/controllers/serializer_controller.rb +18 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cff1f27b341cc49d8383e4757e9b84b9fb90aedb088732684039e366b3f7366
|
4
|
+
data.tar.gz: bf63be47cc9fd48631f3f590ce1d7d8929273a79f8303a3194aed66cda16006c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e3bd30111768c6013ee26c00e323fe49672bf18469a909453e88c28a204c3307cdc4f265bf0e492e269c420991ae5977c3ceb622b38736294fae3e56144d7ef
|
7
|
+
data.tar.gz: c1e00571790e5f9d119976c8bf766e80bd7d03b9f4b4ca25e48f0ed7a083da899d79e3d5f23c5246f1aa2837324c941105ec708389b7e29d206d1d03a7768c62
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@ A useful Rails API generator for scaffolding. Compatible with :
|
|
4
4
|
- Fast JSON API/Active Model Serializers
|
5
5
|
- Rspec/TestUnit/Fixtures/FactoryBot
|
6
6
|
- Api Pagination
|
7
|
+
- Apipie
|
7
8
|
|
8
9
|
## Installation
|
9
10
|
|
@@ -42,7 +43,6 @@ If you wish to specify the api version:
|
|
42
43
|
|
43
44
|
## TODO
|
44
45
|
- Make compatible with nested resources
|
45
|
-
- Add api docs to controller scaffold
|
46
46
|
|
47
47
|
## Contributing
|
48
48
|
|
data/lib/api_scaffold/version.rb
CHANGED
@@ -22,6 +22,10 @@ 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
|
+
|
25
29
|
def test_framework
|
26
30
|
Rails.application.config.generators.options[:rails][:test_framework]
|
27
31
|
end
|
@@ -41,6 +45,7 @@ module ApiScaffold
|
|
41
45
|
def attributes_string
|
42
46
|
attributes_hash.map { |k, v| "#{k}: #{v}" }.join(", ")
|
43
47
|
end
|
48
|
+
|
44
49
|
def attributes_hash
|
45
50
|
return {} if attributes_names.empty?
|
46
51
|
|
@@ -52,6 +57,10 @@ module ApiScaffold
|
|
52
57
|
end
|
53
58
|
end.sort.to_h
|
54
59
|
end
|
60
|
+
|
61
|
+
def apipie_param(attribute)
|
62
|
+
"param :#{attribute.name}, String, 'TODO: #{attribute.name} descrption'"
|
63
|
+
end
|
55
64
|
end
|
56
65
|
end
|
57
66
|
end
|
@@ -6,16 +6,27 @@ 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
|
-
|
9
|
+
<% if apipie_installed? -%>def_param_group :<%= singular_table_name %> do
|
10
|
+
param :<%= singular_table_name %>, Hash, required: true, action_aware: true do
|
11
|
+
<% attributes.each do |attribute| -%><%= indent(apipie_param(attribute), 2) %>
|
12
|
+
<% end -%>end
|
13
|
+
end
|
14
|
+
|
15
|
+
api!
|
16
|
+
<% end -%>def index
|
10
17
|
@<%= plural_table_name %> = <%= 'paginate ' if gem_available?('api-pagination') %><%= orm_class.all(class_name) %>
|
11
18
|
render json: <%= "@#{plural_table_name}" %>
|
12
19
|
end
|
13
20
|
|
21
|
+
<%= 'api!' if apipie_installed? -%>
|
22
|
+
|
14
23
|
def show
|
15
24
|
render json: <%= "@#{singular_table_name}" %>
|
16
25
|
end
|
17
26
|
|
18
|
-
|
27
|
+
<% if apipie_installed? -%>api!
|
28
|
+
param_group :<%= singular_table_name %>
|
29
|
+
<% end -%>def create
|
19
30
|
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
|
20
31
|
|
21
32
|
if @<%= orm_instance.save %>
|
@@ -25,7 +36,9 @@ class <%= prefixed_controller_class_name %>Controller < ApplicationController
|
|
25
36
|
end
|
26
37
|
end
|
27
38
|
|
28
|
-
|
39
|
+
<% if apipie_installed? -%>api!
|
40
|
+
param_group :<%= singular_table_name %>
|
41
|
+
<% end -%>def update
|
29
42
|
if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
30
43
|
render json: <%= "@#{singular_table_name}" %>
|
31
44
|
else
|
@@ -33,6 +46,8 @@ class <%= prefixed_controller_class_name %>Controller < ApplicationController
|
|
33
46
|
end
|
34
47
|
end
|
35
48
|
|
49
|
+
<%= 'api!' if apipie_installed? -%>
|
50
|
+
|
36
51
|
def destroy
|
37
52
|
@<%= orm_instance.destroy %>
|
38
53
|
end
|
@@ -6,16 +6,27 @@ 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
|
-
|
9
|
+
<% if apipie_installed? -%>def_param_group :<%= singular_table_name %> do
|
10
|
+
param :<%= singular_table_name %>, Hash, required: true, action_aware: true do
|
11
|
+
<% attributes.each do |attribute| -%><%= indent(apipie_param(attribute), 2) %>
|
12
|
+
<% end -%>end
|
13
|
+
end
|
14
|
+
|
15
|
+
api!
|
16
|
+
<% end -%>def index
|
10
17
|
@<%= plural_table_name %> = <%= 'paginate ' if gem_available?('api-pagination') %><%= orm_class.all(class_name) %>
|
11
18
|
render json: <%= class_name %>Serializer.new(<%= "@#{plural_table_name}" %>)
|
12
19
|
end
|
13
20
|
|
21
|
+
<%= 'api!' if apipie_installed? -%>
|
22
|
+
|
14
23
|
def show
|
15
24
|
render json: <%= class_name %>Serializer.new(<%= "@#{singular_table_name}" %>)
|
16
25
|
end
|
17
26
|
|
18
|
-
|
27
|
+
<% if apipie_installed? -%>api!
|
28
|
+
param_group :<%= singular_table_name %>
|
29
|
+
<% end -%>def create
|
19
30
|
@<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
|
20
31
|
|
21
32
|
if @<%= orm_instance.save %>
|
@@ -25,7 +36,9 @@ class <%= prefixed_controller_class_name %>Controller < ApplicationController
|
|
25
36
|
end
|
26
37
|
end
|
27
38
|
|
28
|
-
|
39
|
+
<% if apipie_installed? -%>api!
|
40
|
+
param_group :<%= singular_table_name %>
|
41
|
+
<% end -%>def update
|
29
42
|
if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
30
43
|
render json: <%= class_name %>Serializer.new(<%= "@#{singular_table_name}" %>)
|
31
44
|
else
|
@@ -33,6 +46,8 @@ class <%= prefixed_controller_class_name %>Controller < ApplicationController
|
|
33
46
|
end
|
34
47
|
end
|
35
48
|
|
49
|
+
<%= 'api!' if apipie_installed? -%>
|
50
|
+
|
36
51
|
def destroy
|
37
52
|
@<%= orm_instance.destroy %>
|
38
53
|
end
|