api_scaffolding 1.0.2 → 1.0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 18212ce104518b32a3b4b252161d47c91501e599a7982a704b573fa6745bab24
4
- data.tar.gz: aa0a3d7c1ddd955e586dd4248f010c3465a00176e37d0c5a7d38d94e2f624480
3
+ metadata.gz: 9cf16a7cedbb1200b634e5b8c4e1a73c6b47931d6902bfebe6d95f54464de262
4
+ data.tar.gz: 8bc2cead74432092c135b3f25ac0be29671b4cf8b311ef00b374c3b9f3483f44
5
5
  SHA512:
6
- metadata.gz: ff92cd603d95135cddce3443c0e9a0c0dd0554656aed89586b8d0c56201f9bcb2b3f1d621149524e293b01290006eac81696f8abd9cf15d537a268e509cd93c9
7
- data.tar.gz: be967475a4cf3768f9d106824ce624a4a8132bdc01bf81b1ff35e2e6842ee1801da42d5c9e17b9df796ab216a6c5324482d3e257103b926f113f91ef31d3ce90
6
+ metadata.gz: f86d9eafb4a861573437f01e3b6230022da1d6ff97ccb0fe3806b04a7f0547d760a07970e81731acc410870f8379ad0177aa4d9c037dc140a14e07b43fac1d42
7
+ data.tar.gz: 88c3120719bbcaf1ae49c5753b19ada845425f7c70bde3a9cd64fb7be58ec7e1d362389fedcbfe6eb3736b13abde8c1b439b718beab9988c4860dc501bb05cc8
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # API Scaffolding
2
+ [![Gem Version](https://badge.fury.io/rb/api_scaffolding.svg)](https://badge.fury.io/rb/api_scaffolding)
2
3
 
3
4
  Генерация контроллеров API и модулей с параметрами Grape и Grape Entity.
4
5
 
@@ -7,7 +7,9 @@ module ApiScaffolding
7
7
  :params_fields_exclusions,
8
8
  :entity_fields_exclusions,
9
9
  :abilities_check,
10
- :abilities_authorize_opts
10
+ :abilities_authorize_opts,
11
+ :entity_list_parent_class,
12
+ :entity_entry_parent_class
11
13
 
12
14
  def default_api_version
13
15
  @default_api_version || ''
@@ -36,6 +38,14 @@ module ApiScaffolding
36
38
  def abilities_authorize_opts
37
39
  @abilities_authorize_opts || ''
38
40
  end
41
+
42
+ def entity_list_parent_class
43
+ @entity_list_parent_class || 'Grape::Entity'
44
+ end
45
+
46
+ def entity_entry_parent_class
47
+ @entity_entry_parent_class || 'Grape::Entity'
48
+ end
39
49
  end
40
50
 
41
51
  def self.configure
@@ -14,7 +14,7 @@ module ApiScaffold
14
14
  def generate_files
15
15
  generate "api_scaffold:entity #{class_name} --entity_dir=#{options['entity_dir']}"
16
16
  generate "api_scaffold:params_concern #{class_name} --api_version=#{options['api_version']}"
17
- generate "api_scaffold:controller #{class_name} --api_version=#{options['api_version']} --no_params=#{options['no_params']} --no_entity=#{options['no_entity']}"
17
+ generate "api_scaffold:controller #{class_name} --api_version=#{options['api_version']} --no_params=#{options['no_params']} --no_entity=#{options['no_entity']} --entity_dir=#{options['entity_dir']}"
18
18
  generate "api_scaffold:modify_api_root #{class_name} --api_version=#{options['api_version']}"
19
19
  end
20
20
 
@@ -9,6 +9,7 @@ module ApiScaffold
9
9
  class_option :api_version, type: :string, default: ApiScaffolding.config.default_api_version
10
10
  class_option :no_params, type: :boolean, default: false
11
11
  class_option :no_entity, type: :boolean, default: false
12
+ class_option :entity_dir, type: :string, default: nil
12
13
 
13
14
  source_root File.expand_path('../templates', __dir__)
14
15
 
@@ -24,18 +24,6 @@ module ApiScaffold
24
24
 
25
25
  private
26
26
 
27
- def entity_class_name
28
- entity_module_with_prefix + entity_class
29
- end
30
-
31
- def entity_module_with_prefix
32
- dir = options['entity_dir']
33
- value = ApiScaffolding.config.api_version_modules[dir]
34
- return '' if dir.blank? || class_name.starts_with?(value)
35
-
36
- "#{value}::"
37
- end
38
-
39
27
  def list_fields
40
28
  # предполагается, что поля определенные поля должны быть на списке по умолчанию
41
29
  model.columns.map do |column|
@@ -32,6 +32,18 @@ module ApiScaffold
32
32
  "#{class_name}Entity"
33
33
  end
34
34
 
35
+ def entity_class_name
36
+ entity_module_with_prefix + entity_class
37
+ end
38
+
39
+ def entity_module_with_prefix
40
+ dir = options['entity_dir']
41
+ value = ApiScaffolding.config.api_version_modules[dir]
42
+ return '' if dir.blank? || class_name.starts_with?(value)
43
+
44
+ "#{value}::"
45
+ end
46
+
35
47
  def api_address
36
48
  controller_class.underscore
37
49
  end
@@ -16,7 +16,7 @@ module API<%= api_version_module_with_prefix %>
16
16
  <%- if @no_entity -%>
17
17
  desc '<%= api_description %> - список'
18
18
  <%- else -%>
19
- desc '<%= api_description %> - список', entity: <%= entity_class %>::List
19
+ desc '<%= api_description %> - список', entity: <%= entity_class_name %>::List
20
20
  <%- end -%>
21
21
  oauth2
22
22
  <%- unless @no_params -%>
@@ -35,7 +35,7 @@ module API<%= api_version_module_with_prefix %>
35
35
  <%- if @no_entity -%>
36
36
  desc '<%= api_description %> - получение записи'
37
37
  <%- else -%>
38
- desc '<%= api_description %> - получение записи', entity: <%= entity_class %>::Entry
38
+ desc '<%= api_description %> - получение записи', entity: <%= entity_class_name %>::Entry
39
39
  <%- end -%>
40
40
  oauth2
41
41
  <%- if @abilities_check -%>
@@ -47,14 +47,14 @@ module API<%= api_version_module_with_prefix %>
47
47
  <%= class_name %>.find(params[:id])
48
48
  <%- else -%>
49
49
  record = <%= class_name %>.find(params[:id])
50
- present record, with: <%= entity_class %>::Entry
50
+ present record, with: <%= entity_class_name %>::Entry
51
51
  <%- end -%>
52
52
  end
53
53
 
54
54
  <%- if @no_entity -%>
55
55
  desc '<%= api_description %> - создание'
56
56
  <%- else -%>
57
- desc '<%= api_description %> - создание', entity: <%= entity_class %>::Entry
57
+ desc '<%= api_description %> - создание', entity: <%= entity_class_name %>::Entry
58
58
  <%- end -%>
59
59
  oauth2
60
60
  <%- unless @no_params -%>
@@ -72,7 +72,7 @@ module API<%= api_version_module_with_prefix %>
72
72
  <%= class_name %>.create!(attrs)
73
73
  <%- else -%>
74
74
  record = <%= class_name %>.create!(attrs)
75
- present record, with: <%= entity_class %>::Entry
75
+ present record, with: <%= entity_class_name %>::Entry
76
76
  <%- end -%>
77
77
  end
78
78
  <%- if @restoration_required -%>
@@ -80,7 +80,7 @@ module API<%= api_version_module_with_prefix %>
80
80
  <%- if @no_entity -%>
81
81
  desc '<%= api_description %> - восстановление записи'
82
82
  <%- else -%>
83
- desc '<%= api_description %> - восстановление записи', entity: <%= entity_class %>::Entry
83
+ desc '<%= api_description %> - восстановление записи', entity: <%= entity_class_name %>::Entry
84
84
  <%- end -%>
85
85
  oauth2
86
86
  <%- if @abilities_check -%>
@@ -92,7 +92,7 @@ module API<%= api_version_module_with_prefix %>
92
92
  <%- if @no_entity -%>
93
93
  record.restore(recursive: true)
94
94
  <%- else -%>
95
- present record.restore(recursive: true), with: <%= entity_class %>::Entry
95
+ present record.restore(recursive: true), with: <%= entity_class_name %>::Entry
96
96
  <%- end -%>
97
97
  end
98
98
  <%- end -%>
@@ -100,7 +100,7 @@ module API<%= api_version_module_with_prefix %>
100
100
  <%- if @no_entity -%>
101
101
  desc '<%= api_description %> - редактирование'
102
102
  <%- else -%>
103
- desc '<%= api_description %> - редактирование', entity: <%= entity_class %>::Entry
103
+ desc '<%= api_description %> - редактирование', entity: <%= entity_class_name %>::Entry
104
104
  <%- end -%>
105
105
  oauth2
106
106
  <%- unless @no_params -%>
@@ -120,7 +120,7 @@ module API<%= api_version_module_with_prefix %>
120
120
  <%- if @no_entity -%>
121
121
  record
122
122
  <%- else -%>
123
- present record, with: <%= entity_class %>::Entry
123
+ present record, with: <%= entity_class_name %>::Entry
124
124
  <%- end -%>
125
125
  end
126
126
 
@@ -32,6 +32,11 @@ if defined?(ApiScaffold)
32
32
  # deleted_at
33
33
  # ]
34
34
 
35
+ # классы наследования Grape Entity (по умолчанию - Grape::Entity)
36
+ #
37
+ # config.entity_list_parent_class = ''
38
+ # config.entity_entry_parent_class = ''
39
+
35
40
  # список исключений, для которых не будут добавляться поля в классе entity
36
41
  #
37
42
  # config.entity_fields_exclusions = %w[]
@@ -2,12 +2,12 @@
2
2
  class <%= entity_class_name %>
3
3
 
4
4
  # список
5
- class List < BaseEntities::List
5
+ class List < <%= ApiScaffolding.config.entity_list_parent_class %>
6
6
  <%= list_fields %>
7
7
  end
8
8
 
9
9
  # запись
10
- class Entry < BaseEntities::Entry
10
+ class Entry < <%= ApiScaffolding.config.entity_entry_parent_class %>
11
11
  <%= entry_fields %>
12
12
  end
13
13
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_scaffolding
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Павел Бабин
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-07 00:00:00.000000000 Z
11
+ date: 2024-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails