grape-starter 1.5.1 → 1.6.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/.github/workflows/pipeline.yml +4 -4
- data/.rubocop.yml +4 -1
- data/bin/grape-starter +4 -4
- data/grape-starter.gemspec +1 -0
- data/lib/starter/{builder.rb → build.rb} +15 -15
- data/lib/starter/builder/base_file.rb +41 -39
- data/lib/starter/builder/names.rb +61 -59
- data/lib/starter/builder/templates/activerecord.rb +83 -81
- data/lib/starter/builder/templates/endpoints.rb +87 -85
- data/lib/starter/builder/templates/files.rb +54 -52
- data/lib/starter/builder/templates/sequel.rb +78 -76
- data/lib/starter/{builder/file_foo.rb → file_ops.rb} +1 -1
- data/lib/starter/{builder/orms.rb → orms.rb} +9 -9
- data/lib/starter/rake/grape_tasks.rb +0 -2
- data/lib/starter/rspec/request_specs.rb +2 -2
- data/lib/starter/version.rb +1 -1
- data/lib/starter.rb +7 -3
- data/template/Dockerfile +1 -1
- data/template/Gemfile +1 -1
- data/template/Rakefile +2 -2
- data/template/config/boot.rb +1 -1
- data/template/config/puma.rb +10 -0
- data/template/script/server +1 -13
- metadata +21 -8
- data/.travis.yml +0 -24
- data/template/script/stop +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 70eb1ef044b58a9637cb920fcc9129a12ca25392d5d160de75a6ee3ea9483052
|
4
|
+
data.tar.gz: c700ad85e12e2406b11a647d8584d3070d7e6e9c10742fba0909a8182264dff5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c46ea6564c067d4174c29d705482068b991589503928bb5de57f0cfb5b0034485d48a8f3dc7f4b52621110727d6b78f7d86544682ea2d9ebf36054ba00029da8
|
7
|
+
data.tar.gz: ba9e7eb94b6e5412baba003037927310686dae982b439fffb5241d800101c405999c4246ad22c44b175ba3d676c52af632c8f24eb6241cfacab42995e36297d0
|
@@ -12,10 +12,10 @@ jobs:
|
|
12
12
|
rubocop:
|
13
13
|
runs-on: ubuntu-latest
|
14
14
|
steps:
|
15
|
-
- uses: actions/checkout@
|
15
|
+
- uses: actions/checkout@v3
|
16
16
|
- uses: ruby/setup-ruby@v1
|
17
17
|
with:
|
18
|
-
ruby-version: '3.
|
18
|
+
ruby-version: '3.2'
|
19
19
|
bundler-cache: true
|
20
20
|
- name: Run rubocop
|
21
21
|
run: bundle exec rubocop --parallel --format progress
|
@@ -25,10 +25,10 @@ jobs:
|
|
25
25
|
needs: ['rubocop']
|
26
26
|
strategy:
|
27
27
|
matrix:
|
28
|
-
ruby-version: ['
|
28
|
+
ruby-version: ['3.0', '3.1', '3.2', head]
|
29
29
|
|
30
30
|
steps:
|
31
|
-
- uses: actions/checkout@
|
31
|
+
- uses: actions/checkout@v3
|
32
32
|
- name: Set up Ruby
|
33
33
|
uses: ruby/setup-ruby@v1
|
34
34
|
with:
|
data/.rubocop.yml
CHANGED
@@ -14,7 +14,7 @@ AllCops:
|
|
14
14
|
- template/spec/spec-helper.rb
|
15
15
|
UseCache: true
|
16
16
|
NewCops: enable
|
17
|
-
TargetRubyVersion: 3.
|
17
|
+
TargetRubyVersion: 3.2
|
18
18
|
SuggestExtensions: false
|
19
19
|
|
20
20
|
Layout/IndentationWidth:
|
@@ -45,3 +45,6 @@ Style/AsciiComments:
|
|
45
45
|
|
46
46
|
Style/Documentation:
|
47
47
|
Enabled: false
|
48
|
+
|
49
|
+
Style/HashSyntax:
|
50
|
+
Enabled: false # to support ruby 3.0
|
data/bin/grape-starter
CHANGED
@@ -38,7 +38,7 @@ command :new do |c|
|
|
38
38
|
starter_gem = Gem::Specification.find_by_name('grape-starter').gem_dir
|
39
39
|
src = File.join(starter_gem, 'template', '.')
|
40
40
|
|
41
|
-
Starter::
|
41
|
+
Starter::Build.new!(args.first, src, dest, options)
|
42
42
|
$stdout.puts "created: #{args.first}"
|
43
43
|
|
44
44
|
# after creating tasks
|
@@ -71,7 +71,7 @@ command :add do |c|
|
|
71
71
|
|
72
72
|
begin
|
73
73
|
builder_options = global_options.merge(set: set).merge(options)
|
74
|
-
created_files = Starter::
|
74
|
+
created_files = Starter::Build.add!(resource, builder_options)
|
75
75
|
|
76
76
|
`bundle exec rubocop -a #{created_files.join(' ')}`
|
77
77
|
$stdout.puts "added resource: #{resource}"
|
@@ -87,11 +87,11 @@ command :rm do |c|
|
|
87
87
|
c.desc 'removes also entity file'
|
88
88
|
c.switch [:e, :entity], negatable: false
|
89
89
|
|
90
|
-
c.action do |
|
90
|
+
c.action do |_global_options, options, args|
|
91
91
|
exit_now! 'no resource given' if args.empty?
|
92
92
|
resource = args.first
|
93
93
|
|
94
|
-
Starter::
|
94
|
+
Starter::Build.remove!(resource, options)
|
95
95
|
|
96
96
|
$stdout.puts "removed resource: #{resource}"
|
97
97
|
end
|
data/grape-starter.gemspec
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Starter
|
4
|
-
require 'starter/builder/orms'
|
5
|
-
require 'starter/builder/names'
|
6
|
-
require 'starter/builder/base_file'
|
7
|
-
require 'starter/builder/file_foo'
|
8
|
-
require 'starter/builder/templates/files'
|
9
|
-
require 'starter/builder/templates/endpoints'
|
10
|
-
|
11
|
-
class
|
12
|
-
extend Names
|
13
|
-
extend BaseFile
|
14
|
-
extend Templates::Files
|
15
|
-
extend Templates::Endpoints
|
4
|
+
# require 'starter/builder/orms'
|
5
|
+
# require 'starter/builder/names'
|
6
|
+
# require 'starter/builder/base_file'
|
7
|
+
# require 'starter/builder/file_foo'
|
8
|
+
# require 'starter/builder/templates/files'
|
9
|
+
# require 'starter/builder/templates/endpoints'
|
10
|
+
|
11
|
+
class Build
|
12
|
+
extend Builder::Names
|
13
|
+
extend Builder::BaseFile
|
14
|
+
extend Builder::Templates::Files
|
15
|
+
extend Builder::Templates::Endpoints
|
16
16
|
|
17
17
|
class << self
|
18
18
|
attr_reader :prefix, :resource, :set, :force, :entity, :destination, :orm
|
@@ -120,7 +120,7 @@ module Starter
|
|
120
120
|
# creates a new file in lib folder as namespace, includind the version
|
121
121
|
def add_namespace_with_version
|
122
122
|
new_lib = File.join(destination, 'lib', base_file_name)
|
123
|
-
|
123
|
+
FileOps.write_file(new_lib, base_namespace_file.strip_heredoc)
|
124
124
|
end
|
125
125
|
|
126
126
|
#
|
@@ -128,7 +128,7 @@ module Starter
|
|
128
128
|
def replace_static(file, replacement)
|
129
129
|
file_path = File.join(destination, file)
|
130
130
|
|
131
|
-
|
131
|
+
FileOps.call!(file_path) { |content| content.gsub!('{{{grape-starter}}}', replacement.to_s) }
|
132
132
|
end
|
133
133
|
|
134
134
|
# #add! a new resource releated helper methods
|
@@ -159,7 +159,7 @@ module Starter
|
|
159
159
|
def save_file(new_file)
|
160
160
|
new_file_name = send("#{new_file}_name")
|
161
161
|
should_raise?(new_file_name)
|
162
|
-
|
162
|
+
FileOps.write_file(new_file_name, send(new_file.strip_heredoc))
|
163
163
|
end
|
164
164
|
|
165
165
|
#
|
@@ -1,45 +1,47 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Starter
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
file
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
4
|
+
module Builder
|
5
|
+
module BaseFile
|
6
|
+
# add it in api base
|
7
|
+
def add_mount_point
|
8
|
+
FileOps.call!(api_base_file_name) { |content| add_to_base(content) }
|
9
|
+
end
|
10
|
+
|
11
|
+
# adding mount point to base class
|
12
|
+
def add_to_base(file)
|
13
|
+
occurence = file.scan(/(\s+mount\s.*?\n)/).last.first
|
14
|
+
replacement = occurence + mount_point
|
15
|
+
file.sub!(occurence, replacement)
|
16
|
+
end
|
17
|
+
|
18
|
+
# removes in api base
|
19
|
+
def remove_mount_point
|
20
|
+
FileOps.call!(api_base_file_name) { |content| remove_from_base(content) }
|
21
|
+
end
|
22
|
+
|
23
|
+
# removes mount point from base class
|
24
|
+
def remove_from_base(file)
|
25
|
+
file.sub!(mount_point, '')
|
26
|
+
end
|
27
|
+
|
28
|
+
# parses out the prefix from base api file
|
29
|
+
def base_prefix
|
30
|
+
Starter::Config.read[:prefix]
|
31
|
+
end
|
32
|
+
|
33
|
+
# parses out the version from base api file
|
34
|
+
def base_version
|
35
|
+
base_file
|
36
|
+
|
37
|
+
base_file.scan(/version\s+(.+),/).first.first.delete!("'")
|
38
|
+
end
|
39
|
+
|
40
|
+
# get api base file as string
|
41
|
+
def base_file
|
42
|
+
file = File.join(Dir.getwd, 'api', 'base.rb')
|
43
|
+
FileOps.read_file(file)
|
44
|
+
end
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
@@ -1,80 +1,82 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Starter
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
module Builder
|
5
|
+
module Names
|
6
|
+
def klass_name
|
7
|
+
for_klass = prepare_klass
|
8
|
+
singular? ? for_klass.classify : for_klass.classify.pluralize
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
-
|
11
|
+
def lib_klass_name
|
12
|
+
return klass_name unless @orm
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
14
|
+
case Starter::Config.read[:orm]
|
15
|
+
when 'sequel'
|
16
|
+
require 'starter/builder/templates/sequel'
|
17
|
+
extend(Starter::Builder::Templates::Sequel)
|
18
|
+
"#{klass_name} < #{model_klass}"
|
19
|
+
when 'activerecord', 'ar'
|
20
|
+
require 'starter/builder/templates/activerecord'
|
21
|
+
extend(Starter::Builder::Templates::ActiveRecord)
|
22
|
+
"#{klass_name} < #{model_klass}"
|
23
|
+
else
|
24
|
+
klass_name
|
25
|
+
end
|
24
26
|
end
|
25
|
-
end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
# rubocop:disable Style/StringConcatenation
|
29
|
+
def base_file_name
|
30
|
+
@resource.tr('/', '-').downcase + '.rb'
|
31
|
+
end
|
32
|
+
# rubocop:enable Style/StringConcatenation
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
def base_spec_name
|
35
|
+
base_file_name.gsub(/.rb$/, '_spec.rb')
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
38
|
+
def mount_point
|
39
|
+
" mount Endpoints::#{klass_name}\n"
|
40
|
+
end
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
42
|
+
def api_base_file_name
|
43
|
+
File.join(Dir.getwd, 'api', 'base.rb')
|
44
|
+
end
|
44
45
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
# resource file
|
47
|
+
def api_file_name
|
48
|
+
File.join(Dir.getwd, 'api', 'endpoints', base_file_name)
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
# resource file
|
52
|
+
def entity_file_name
|
53
|
+
File.join(Dir.getwd, 'api', 'entities', base_file_name)
|
54
|
+
end
|
54
55
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
# lib file
|
57
|
+
def lib_file_name
|
58
|
+
File.join(Dir.getwd, 'lib', 'models', base_file_name)
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
# resource spec
|
62
|
+
def api_spec_name
|
63
|
+
File.join(Dir.getwd, 'spec', 'requests', base_spec_name)
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
# lib spec
|
67
|
+
def lib_spec_name
|
68
|
+
File.join(Dir.getwd, 'spec', 'lib', 'models', base_spec_name)
|
69
|
+
end
|
69
70
|
|
70
|
-
|
71
|
+
private
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
|
73
|
+
def prepare_klass
|
74
|
+
@resource.tr('-', '/')
|
75
|
+
end
|
75
76
|
|
76
|
-
|
77
|
-
|
77
|
+
def singular?
|
78
|
+
@resource.singularize.inspect == @resource.inspect
|
79
|
+
end
|
78
80
|
end
|
79
81
|
end
|
80
82
|
end
|
@@ -3,102 +3,104 @@
|
|
3
3
|
require 'active_record'
|
4
4
|
|
5
5
|
module Starter
|
6
|
-
module
|
7
|
-
module
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
module Builder
|
7
|
+
module Templates
|
8
|
+
module ActiveRecord
|
9
|
+
def model_klass
|
10
|
+
'ActiveRecord::Base'
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
13
|
+
def initializer
|
14
|
+
<<-FILE.strip_heredoc
|
15
|
+
# frozen_string_literal: true
|
16
|
+
|
17
|
+
require 'yaml'
|
18
|
+
require 'erb'
|
19
|
+
require 'active_record'
|
20
|
+
|
21
|
+
config_content = File.read(File.join('config', 'database.yml'))
|
22
|
+
|
23
|
+
db_conf = YAML.safe_load(ERB.new(config_content).result)
|
24
|
+
env = ENV['RACK_ENV'] || 'development'
|
25
|
+
|
26
|
+
ActiveRecord::Base.establish_connection db_conf[env]
|
27
|
+
logger = if %w[development test].include? env
|
28
|
+
log_dir = File.join(Dir.getwd, 'log')
|
29
|
+
log_file = File.join(log_dir, 'db.log')
|
30
|
+
FileUtils.mkdir(log_dir) unless Dir.exist?(log_dir)
|
31
|
+
Logger.new(File.open(log_file, 'a'))
|
32
|
+
else
|
33
|
+
Logger.new($stdout)
|
34
|
+
end
|
35
|
+
|
36
|
+
ActiveRecord::Base.logger = logger
|
37
|
+
|
38
|
+
# Middleware
|
39
|
+
module ActiveRecord
|
40
|
+
module Rack
|
41
|
+
# ActiveRecord >= 5 removes the Pool management
|
42
|
+
class ConnectionManagement
|
43
|
+
def initialize(app)
|
44
|
+
@app = app
|
45
|
+
end
|
46
|
+
|
47
|
+
def call(env)
|
48
|
+
response = @app.call(env)
|
49
|
+
response[2] = ::Rack::BodyProxy.new(response[2]) do
|
50
|
+
ActiveRecord::Base.clear_active_connections!
|
51
|
+
end
|
45
52
|
|
46
|
-
|
47
|
-
|
48
|
-
response[2] = ::Rack::BodyProxy.new(response[2]) do
|
53
|
+
return response
|
54
|
+
rescue StandardError
|
49
55
|
ActiveRecord::Base.clear_active_connections!
|
56
|
+
raise
|
50
57
|
end
|
51
|
-
|
52
|
-
return response
|
53
|
-
rescue StandardError
|
54
|
-
ActiveRecord::Base.clear_active_connections!
|
55
|
-
raise
|
56
58
|
end
|
57
59
|
end
|
58
60
|
end
|
61
|
+
FILE
|
59
62
|
end
|
60
|
-
FILE
|
61
|
-
end
|
62
63
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
64
|
+
def rakefile
|
65
|
+
<<-FILE.strip_heredoc
|
66
|
+
# ActiveRecord migration tasks
|
67
|
+
require 'active_record'
|
68
|
+
include ActiveRecord::Tasks
|
69
|
+
config_dir = File.expand_path('../config', __FILE__)
|
70
|
+
config_content = File.join(config_dir, 'database.yml')
|
71
|
+
DatabaseTasks.env = ENV['RACK_ENV'] || 'development'
|
72
|
+
DatabaseTasks.database_configuration = YAML.load_file(config_content)
|
73
|
+
DatabaseTasks.db_dir = 'db'
|
74
|
+
DatabaseTasks.migrations_paths = File.join('db', 'migrate')
|
75
|
+
|
76
|
+
ActiveRecord::Base.configurations = DatabaseTasks.database_configuration
|
77
|
+
ActiveRecord::Base.establish_connection DatabaseTasks.env.to_sym
|
78
|
+
|
79
|
+
load 'active_record/railties/databases.rake'
|
80
|
+
FILE
|
81
|
+
end
|
81
82
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
83
|
+
def gemfile
|
84
|
+
<<-FILE.strip_heredoc
|
85
|
+
# DB stuff
|
86
|
+
gem 'activerecord', '>= 6'
|
87
|
+
gem 'pg'
|
88
|
+
FILE
|
89
|
+
end
|
89
90
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
91
|
+
def migration(klass_name, resource)
|
92
|
+
version = "#{::ActiveRecord::VERSION::MAJOR}.#{::ActiveRecord::VERSION::MINOR}"
|
93
|
+
<<-FILE.strip_heredoc
|
94
|
+
class Create#{klass_name} < ActiveRecord::Migration[#{version}]
|
95
|
+
def change
|
96
|
+
create_table :#{resource} do |t|
|
96
97
|
|
97
|
-
|
98
|
+
t.timestamps
|
99
|
+
end
|
98
100
|
end
|
99
101
|
end
|
102
|
+
FILE
|
100
103
|
end
|
101
|
-
FILE
|
102
104
|
end
|
103
105
|
end
|
104
106
|
end
|