grape-starter 1.6.1 → 1.6.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/pipeline.yml +2 -0
- data/lib/starter/build.rb +10 -7
- data/lib/starter/builder/base_file.rb +4 -4
- data/lib/starter/builder/names.rb +32 -26
- data/lib/starter/templates/files.rb +5 -5
- data/lib/starter/version.rb +1 -1
- 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: a0e8dbdcdf0bc8ec707834a2a55a2c36826c316d82a45f7f8c219e1ec4361f37
|
4
|
+
data.tar.gz: 21d235ca4a99f447965c8cf9a765bfaabca150f74a493ee332fb60aa137ce7fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c54cbaf4ce481b619e621c733a6b16bd1582761a297e4380de381773c837d3a0894a472f6e45bf451ad702fa5ca8fe1d0abcf8c067f31844d5eb75532cfec7cf
|
7
|
+
data.tar.gz: df826306d1964ed1f2a58f87353cfb03b6f86bb084b0cb70e14639b04748d18986e5d971be420efb12919b82a28042cf8e1147e0c938eb5a52c0ef4ed44694ae
|
data/lib/starter/build.rb
CHANGED
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
module Starter
|
4
4
|
class Build
|
5
|
-
extend Builder::Names
|
6
5
|
extend Builder::BaseFile
|
7
6
|
extend Templates::Files
|
8
7
|
extend Templates::Endpoints
|
9
8
|
|
10
9
|
class << self
|
11
|
-
attr_reader :prefix, :resource, :
|
10
|
+
attr_reader :prefix, :resource, :entity,
|
11
|
+
:set, :force, :destination, :orm,
|
12
|
+
:naming
|
12
13
|
|
13
14
|
#
|
14
15
|
# public methods
|
@@ -27,6 +28,7 @@ module Starter
|
|
27
28
|
@resource = name
|
28
29
|
@destination = destination
|
29
30
|
@prefix = options[:p] # can be nil
|
31
|
+
@naming = Starter::Builder::Names.new(@resource)
|
30
32
|
|
31
33
|
FileUtils.copy_entry source, destination
|
32
34
|
|
@@ -62,8 +64,9 @@ module Starter
|
|
62
64
|
@force = options[:force]
|
63
65
|
@entity = options[:entity]
|
64
66
|
@orm = options[:orm]
|
67
|
+
@naming = Starter::Builder::Names.new(@resource)
|
65
68
|
|
66
|
-
Orms.add_migration(klass_name, resource.downcase) if @orm
|
69
|
+
Orms.add_migration(@naming.klass_name, resource.downcase) if @orm
|
67
70
|
save_resource
|
68
71
|
end
|
69
72
|
|
@@ -112,7 +115,7 @@ module Starter
|
|
112
115
|
#
|
113
116
|
# creates a new file in lib folder as namespace, includind the version
|
114
117
|
def add_namespace_with_version
|
115
|
-
new_lib = File.join(destination, 'lib', base_file_name)
|
118
|
+
new_lib = File.join(destination, 'lib', @naming.base_file_name)
|
116
119
|
FileOps.write_file(new_lib, base_namespace_file.strip_heredoc)
|
117
120
|
end
|
118
121
|
|
@@ -128,7 +131,7 @@ module Starter
|
|
128
131
|
#
|
129
132
|
# provides an array of endpoints for the new resource
|
130
133
|
def endpoint_set
|
131
|
-
crud_set = singular? ? singular_one : crud
|
134
|
+
crud_set = @naming.singular? ? singular_one : crud
|
132
135
|
return crud_set if set.blank?
|
133
136
|
|
134
137
|
crud_set.each_with_object([]) { |x, memo| set.map { |y| memo << x if x.to_s.start_with?(y) } }
|
@@ -138,7 +141,7 @@ module Starter
|
|
138
141
|
# saves all resource related files
|
139
142
|
def save_resource
|
140
143
|
created_files = file_list.each_with_object([]) do |new_file, memo|
|
141
|
-
memo << send("#{new_file}_name")
|
144
|
+
memo << @naming.send("#{new_file}_name")
|
142
145
|
save_file(new_file)
|
143
146
|
end
|
144
147
|
|
@@ -150,7 +153,7 @@ module Starter
|
|
150
153
|
#
|
151
154
|
# saves new resource files
|
152
155
|
def save_file(new_file)
|
153
|
-
new_file_name = send("#{new_file}_name")
|
156
|
+
new_file_name = @naming.send("#{new_file}_name")
|
154
157
|
should_raise?(new_file_name)
|
155
158
|
FileOps.write_file(new_file_name, send(new_file.strip_heredoc))
|
156
159
|
end
|
@@ -5,24 +5,24 @@ module Starter
|
|
5
5
|
module BaseFile
|
6
6
|
# add it in api base
|
7
7
|
def add_mount_point
|
8
|
-
FileOps.call!(api_base_file_name) { |content| add_to_base(content) }
|
8
|
+
FileOps.call!(@naming.api_base_file_name) { |content| add_to_base(content) }
|
9
9
|
end
|
10
10
|
|
11
11
|
# adding mount point to base class
|
12
12
|
def add_to_base(file)
|
13
13
|
occurence = file.scan(/(\s+mount\s.*?\n)/).last.first
|
14
|
-
replacement = occurence + mount_point
|
14
|
+
replacement = occurence + @naming.mount_point
|
15
15
|
file.sub!(occurence, replacement)
|
16
16
|
end
|
17
17
|
|
18
18
|
# removes in api base
|
19
19
|
def remove_mount_point
|
20
|
-
FileOps.call!(api_base_file_name) { |content| remove_from_base(content) }
|
20
|
+
FileOps.call!(@naming.api_base_file_name) { |content| remove_from_base(content) }
|
21
21
|
end
|
22
22
|
|
23
23
|
# removes mount point from base class
|
24
24
|
def remove_from_base(file)
|
25
|
-
file.sub!(mount_point, '')
|
25
|
+
file.sub!(@naming.mount_point, '')
|
26
26
|
end
|
27
27
|
|
28
28
|
# parses out the prefix from base api file
|
@@ -2,51 +2,41 @@
|
|
2
2
|
|
3
3
|
module Starter
|
4
4
|
module Builder
|
5
|
-
|
5
|
+
class Names
|
6
|
+
def initialize(resource)
|
7
|
+
@resource = resource
|
8
|
+
end
|
9
|
+
|
6
10
|
def klass_name
|
7
11
|
for_klass = prepare_klass
|
8
12
|
singular? ? for_klass.classify : for_klass.classify.pluralize
|
9
13
|
end
|
10
14
|
|
11
|
-
def lib_klass_name
|
12
|
-
return klass_name unless @orm
|
13
|
-
|
14
|
-
case Starter::Config.read[:orm]
|
15
|
-
when 'sequel'
|
16
|
-
extend(Starter::Builder::Sequel)
|
17
|
-
"#{klass_name} < #{model_klass}"
|
18
|
-
when 'activerecord', 'ar'
|
19
|
-
extend(Starter::Builder::ActiveRecord)
|
20
|
-
"#{klass_name} < #{model_klass}"
|
21
|
-
else
|
22
|
-
klass_name
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
15
|
# rubocop:disable Style/StringConcatenation
|
27
16
|
def base_file_name
|
28
17
|
@resource.tr('/', '-').downcase + '.rb'
|
29
18
|
end
|
30
19
|
# rubocop:enable Style/StringConcatenation
|
31
20
|
|
21
|
+
def api_base_file_name
|
22
|
+
File.join(Dir.getwd, 'api', 'base.rb')
|
23
|
+
end
|
24
|
+
|
32
25
|
def base_spec_name
|
33
26
|
base_file_name.gsub(/.rb$/, '_spec.rb')
|
34
27
|
end
|
35
28
|
|
29
|
+
# entry in api/base.rb
|
36
30
|
def mount_point
|
37
31
|
" mount Endpoints::#{klass_name}\n"
|
38
32
|
end
|
39
33
|
|
40
|
-
|
41
|
-
File.join(Dir.getwd, 'api', 'base.rb')
|
42
|
-
end
|
43
|
-
|
44
|
-
# resource file
|
34
|
+
# endpoints file
|
45
35
|
def api_file_name
|
46
36
|
File.join(Dir.getwd, 'api', 'endpoints', base_file_name)
|
47
37
|
end
|
48
38
|
|
49
|
-
#
|
39
|
+
# entities file
|
50
40
|
def entity_file_name
|
51
41
|
File.join(Dir.getwd, 'api', 'entities', base_file_name)
|
52
42
|
end
|
@@ -56,6 +46,22 @@ module Starter
|
|
56
46
|
File.join(Dir.getwd, 'lib', 'models', base_file_name)
|
57
47
|
end
|
58
48
|
|
49
|
+
# model entry in lib file
|
50
|
+
def lib_klass_name
|
51
|
+
return klass_name unless @orm
|
52
|
+
|
53
|
+
case Starter::Config.read[:orm]
|
54
|
+
when 'sequel'
|
55
|
+
extend(Starter::Builder::Sequel)
|
56
|
+
"#{klass_name} < #{model_klass}"
|
57
|
+
when 'activerecord', 'ar'
|
58
|
+
extend(Starter::Builder::ActiveRecord)
|
59
|
+
"#{klass_name} < #{model_klass}"
|
60
|
+
else
|
61
|
+
klass_name
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
59
65
|
# resource spec
|
60
66
|
def api_spec_name
|
61
67
|
File.join(Dir.getwd, 'spec', 'requests', base_spec_name)
|
@@ -66,15 +72,15 @@ module Starter
|
|
66
72
|
File.join(Dir.getwd, 'spec', 'lib', 'models', base_spec_name)
|
67
73
|
end
|
68
74
|
|
75
|
+
def singular?
|
76
|
+
@resource.singularize.inspect == @resource.inspect
|
77
|
+
end
|
78
|
+
|
69
79
|
private
|
70
80
|
|
71
81
|
def prepare_klass
|
72
82
|
@resource.tr('-', '/')
|
73
83
|
end
|
74
|
-
|
75
|
-
def singular?
|
76
|
-
@resource.singularize.inspect == @resource.inspect
|
77
|
-
end
|
78
84
|
end
|
79
85
|
end
|
80
86
|
end
|
@@ -10,7 +10,7 @@ module Starter
|
|
10
10
|
|
11
11
|
module Api
|
12
12
|
module Endpoints
|
13
|
-
class #{klass_name} < Grape::API
|
13
|
+
class #{@naming.klass_name} < Grape::API
|
14
14
|
namespace :#{resource.downcase} do
|
15
15
|
#{endpoints}
|
16
16
|
end
|
@@ -26,7 +26,7 @@ module Starter
|
|
26
26
|
|
27
27
|
module Api
|
28
28
|
module Entities
|
29
|
-
class #{klass_name} < Grape::Entity
|
29
|
+
class #{@naming.klass_name} < Grape::Entity
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -38,7 +38,7 @@ module Starter
|
|
38
38
|
<<-FILE.strip_heredoc
|
39
39
|
# frozen_string_literal: true
|
40
40
|
|
41
|
-
module #{klass_name}
|
41
|
+
module #{@naming.klass_name}
|
42
42
|
VERSION = '0.1.0'
|
43
43
|
end
|
44
44
|
FILE
|
@@ -49,7 +49,7 @@ module Starter
|
|
49
49
|
# frozen_string_literal: true
|
50
50
|
|
51
51
|
module Models
|
52
|
-
class #{lib_klass_name}
|
52
|
+
class #{@naming.lib_klass_name}
|
53
53
|
end
|
54
54
|
end
|
55
55
|
FILE
|
@@ -74,7 +74,7 @@ module Starter
|
|
74
74
|
|
75
75
|
require 'spec_helper'
|
76
76
|
|
77
|
-
RSpec.describe Models::#{klass_name} do
|
77
|
+
RSpec.describe Models::#{@naming.klass_name} do
|
78
78
|
pending 'write specs'
|
79
79
|
end
|
80
80
|
FILE
|
data/lib/starter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-starter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LeFnord
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|