api_scaffold 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b849a097b4d3de796e261221a6d46245f92eb5abf6cdc5b169b6113896612594
4
- data.tar.gz: a9c0066a65c33bd6a5a95b72af2e231df9a472c3dd7fdc42431c5c07f165e68c
3
+ metadata.gz: 8cff1f27b341cc49d8383e4757e9b84b9fb90aedb088732684039e366b3f7366
4
+ data.tar.gz: bf63be47cc9fd48631f3f590ce1d7d8929273a79f8303a3194aed66cda16006c
5
5
  SHA512:
6
- metadata.gz: a4fd95d6617e0286e26c07f80be7930731643bf8c4f84970a5c1224a4b28dc7050eb983487d8dfa9de42822a945554ed4a1dc80b79e77c0b60c1704241b2c984
7
- data.tar.gz: 8c33ea95c27483219ee09595956486556b36716bc28e43c81be98398d7854cc047ebebed894296dc9f6b5d222eebe4771ed7615070ec5b26d107c42ca042ecf1
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
 
@@ -1,3 +1,3 @@
1
1
  module ApiScaffold
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -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
- def index
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
- def create
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
- def update
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
- def index
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
- def create
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
- def update
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefan Atkinson