api_scaffolding 1.0.3 → 1.1.0
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/lib/generators/api_scaffold/api_scaffold_generator.rb +1 -1
- data/lib/generators/api_scaffold/controller_generator.rb +1 -0
- data/lib/generators/api_scaffold/entity_generator.rb +21 -22
- data/lib/generators/api_scaffold/helper.rb +12 -0
- data/lib/generators/api_scaffold/params_concern_generator.rb +7 -2
- data/lib/generators/templates/api_controller.rb.tt +9 -9
- metadata +18 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08c5ec74d829c952e8a2ceb573f4730efad6a959079353cc1b7d64ff04fced97'
|
4
|
+
data.tar.gz: 17aac17e0026af1f9aa8edb11606c4abf8e6817dc77720c45b183cbaeb890b7b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba57f6f99006c3933af779cfd849e491a64392bd053a6b18b1bd215723c52c762d3b3d2de3634b233d285a0aef0931b3d0ac83030765e3384130e9417ca693ef
|
7
|
+
data.tar.gz: 84caddd41decc1abced9faf367ec2f75dc32651d967e2d475b958b7987717ea6e634751b2c8632229739b1f72a774ca293d85eddea8ab16cc95ad16934ccf4ce
|
@@ -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,24 +24,12 @@ 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|
|
42
30
|
next if %w[name].exclude?(column.name)
|
43
31
|
|
44
|
-
entity_field(column)
|
32
|
+
entity_field(column).force_encoding(Encoding::BINARY)
|
45
33
|
end.compact.join(fields_separator)
|
46
34
|
end
|
47
35
|
|
@@ -50,29 +38,40 @@ module ApiScaffold
|
|
50
38
|
model.columns.map do |column|
|
51
39
|
next if ApiScaffolding.config.entity_fields_exclusions.include?(column.name)
|
52
40
|
|
53
|
-
entity_field(column)
|
41
|
+
entity_field(column).force_encoding(Encoding::BINARY)
|
54
42
|
end.compact.join(fields_separator)
|
55
43
|
end
|
56
44
|
|
57
45
|
def fields_separator
|
58
46
|
# разделение полей в генерируемом файле
|
59
|
-
"\n" + (' ' * 4)
|
47
|
+
"\n\n" + (' ' * 4)
|
60
48
|
end
|
61
49
|
|
62
50
|
def entity_field(column)
|
51
|
+
# разделение для форматирования поля
|
52
|
+
separator = "\n" + (' ' * 11)
|
53
|
+
|
54
|
+
# описание поля
|
55
|
+
desc = column.comment
|
56
|
+
if column.type == :enum
|
57
|
+
desc += " (enum: #{column.sql_type})"
|
58
|
+
end
|
59
|
+
|
63
60
|
case column.type
|
64
|
-
when :string
|
65
|
-
"expose :#{column.name}"
|
61
|
+
when :string
|
62
|
+
"expose :#{column.name},#{separator}documentation: { desc: '#{desc}' }"
|
63
|
+
when :enum
|
64
|
+
"expose :#{column.name},#{separator}documentation: { values: #{model}.#{column.name.pluralize}.values, desc: '#{desc}' }"
|
66
65
|
when :integer
|
67
|
-
"expose :#{column.name}
|
66
|
+
"expose :#{column.name},#{separator}documentation: { type: 'Integer', desc: '#{desc}' }"
|
68
67
|
when :float
|
69
|
-
"expose :#{column.name}
|
68
|
+
"expose :#{column.name},#{separator}documentation: { type: 'Float', desc: '#{desc}' }"
|
70
69
|
when :decimal
|
71
|
-
"expose :#{column.name}
|
70
|
+
"expose :#{column.name},#{separator}documentation: { type: 'Float', values: [#{decimal_example(column)}], desc: '#{desc}' }"
|
72
71
|
when :date
|
73
|
-
"expose :#{column.name}
|
72
|
+
"expose :#{column.name},#{separator}documentation: { type: 'Date', desc: '#{desc}' }"
|
74
73
|
when :boolean
|
75
|
-
"expose :#{column.name}
|
74
|
+
"expose :#{column.name},#{separator}documentation: { type: 'Boolean', desc: '#{desc}' }"
|
76
75
|
end
|
77
76
|
end
|
78
77
|
|
@@ -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
|
@@ -37,11 +37,16 @@ module ApiScaffold
|
|
37
37
|
when :decimal
|
38
38
|
'Float'
|
39
39
|
else
|
40
|
-
column.type.capitalize
|
40
|
+
column.type.to_s.capitalize
|
41
41
|
end
|
42
42
|
|
43
43
|
# базовая строка
|
44
|
-
line = "optional :#{column.name}
|
44
|
+
line = "optional :#{column.name}"
|
45
|
+
|
46
|
+
# добавление типа
|
47
|
+
if type != 'String'
|
48
|
+
line += ", type: #{type}"
|
49
|
+
end
|
45
50
|
|
46
51
|
# добавление возможных значений enum
|
47
52
|
if column.type == :enum
|
@@ -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: <%=
|
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: <%=
|
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: <%=
|
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: <%=
|
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: <%=
|
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: <%=
|
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: <%=
|
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: <%=
|
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: <%=
|
123
|
+
present record, with: <%= entity_class_name %>::Entry
|
124
124
|
<%- end -%>
|
125
125
|
end
|
126
126
|
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_scaffolding
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Павел Бабин
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '6.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '6.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -31,6 +31,9 @@ dependencies:
|
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.7.0
|
34
|
+
- - "~>"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '1.7'
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -38,6 +41,9 @@ dependencies:
|
|
38
41
|
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: 1.7.0
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.7'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: grape-entity
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -45,6 +51,9 @@ dependencies:
|
|
45
51
|
- - ">="
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: 1.0.0
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '1.0'
|
48
57
|
type: :runtime
|
49
58
|
prerelease: false
|
50
59
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -52,18 +61,21 @@ dependencies:
|
|
52
61
|
- - ">="
|
53
62
|
- !ruby/object:Gem::Version
|
54
63
|
version: 1.0.0
|
64
|
+
- - "~>"
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '1.0'
|
55
67
|
- !ruby/object:Gem::Dependency
|
56
68
|
name: faker
|
57
69
|
requirement: !ruby/object:Gem::Requirement
|
58
70
|
requirements:
|
59
|
-
- - "
|
71
|
+
- - "~>"
|
60
72
|
- !ruby/object:Gem::Version
|
61
73
|
version: '3.0'
|
62
74
|
type: :runtime
|
63
75
|
prerelease: false
|
64
76
|
version_requirements: !ruby/object:Gem::Requirement
|
65
77
|
requirements:
|
66
|
-
- - "
|
78
|
+
- - "~>"
|
67
79
|
- !ruby/object:Gem::Version
|
68
80
|
version: '3.0'
|
69
81
|
description: Генерация контроллеров API и модулей с параметрами Grape и Grape Entity
|