grape-starter 0.8.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.rspec +2 -0
- data/.travis.yml +8 -3
- data/CHANGELOG.md +6 -0
- data/Gemfile +4 -3
- data/README.md +3 -2
- data/bin/grape-starter +2 -0
- data/lib/starter/builder.rb +27 -16
- data/lib/starter/builder/orms.rb +28 -12
- data/lib/starter/builder/templates/activerecord.rb +13 -0
- data/lib/starter/builder/templates/sequel.rb +15 -0
- data/lib/starter/version.rb +1 -1
- data/template/Gemfile +0 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e073b45cc89020c1371c9d38206265d3bdf4087316dfc12988394663eb10f935
|
4
|
+
data.tar.gz: 1446043c5698906fac0f89342f73a27dfbc7e252d2ac1a121be61ae0d25599a2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c42f38b0c69e3661b655802276ba280b5c104e289d86ab100fbba572692dd11fe9d558f5cec35927b9fc8617ca8c876fdc26abaaad609aaed86521bb7941fa37
|
7
|
+
data.tar.gz: d894032459bf6daf5ea08386313944251f77cfca81d18b7b9fbd4347db0f7f750294fa5e6d6fcaceccd22d3f273753c9c483be5a9290a10826b5ad237a6a74e1
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.travis.yml
CHANGED
@@ -7,11 +7,16 @@ before_install:
|
|
7
7
|
- gem install bundler
|
8
8
|
|
9
9
|
rvm:
|
10
|
-
- 2.5.
|
11
|
-
- 2.4.
|
12
|
-
- ruby-head
|
10
|
+
- 2.5.1
|
11
|
+
- 2.4.4
|
13
12
|
|
14
13
|
matrix:
|
15
14
|
fast_finish: true
|
15
|
+
|
16
|
+
include:
|
17
|
+
- rvm: ruby-head
|
18
|
+
- rvm: 2.3.7
|
19
|
+
|
16
20
|
allow_failures:
|
17
21
|
- rvm: ruby-head
|
22
|
+
- rvm: 2.3.7
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
- contributions
|
4
4
|
|
5
|
+
### 1.0.0
|
6
|
+
|
7
|
+
- [67a5f](https://github.com/LeFnord/grape-starter/commit/b1f32801844ed9a98bc4d5f7c938451ef7667a5f) - supports creating a migration file
|
8
|
+
- [de26b](https://github.com/LeFnord/grape-starter/commit/22ad2170176b9602cff2239a7d0469c823cde26b) - ci adoptions
|
9
|
+
- [7ad69](https://github.com/LeFnord/grape-starter/commit/925fa5fb161c8cc26c96834e185d8299a207ad69) - spec improvements
|
10
|
+
|
5
11
|
### 0.8.7
|
6
12
|
|
7
13
|
- [c7cb2](https://github.com/LeFnord/grape-starter/commit/4be5bd9b7c06611e096d6eaa23d7168136bc7cb2) - updates dependencies; makes rubocop happy
|
data/Gemfile
CHANGED
@@ -5,11 +5,12 @@ source 'http://rubygems.org'
|
|
5
5
|
gemspec
|
6
6
|
|
7
7
|
group :development, :test do
|
8
|
-
gem 'grape', '
|
8
|
+
gem 'grape', '~> 1.0'
|
9
9
|
gem 'pry', platforms: [:mri]
|
10
10
|
gem 'pry-byebug', platforms: [:mri]
|
11
11
|
gem 'rack-cors', require: false
|
12
12
|
gem 'rack-test', require: false
|
13
|
-
gem 'rake', '
|
14
|
-
gem 'rspec', '
|
13
|
+
gem 'rake', '~> 12.0'
|
14
|
+
gem 'rspec', '~> 3.7'
|
15
|
+
gem 'rspec-command'
|
15
16
|
end
|
data/README.md
CHANGED
@@ -97,8 +97,9 @@ This adds endpoint and lib file and belonging specs, and a mount entry in base.r
|
|
97
97
|
|
98
98
|
Using it with following options:
|
99
99
|
```
|
100
|
-
-e, --entity
|
101
|
-
-
|
100
|
+
-e, --entity # a grape entity file will also be created
|
101
|
+
-m, --migration # adds also a migration file, if an ORM is used
|
102
|
+
-o, --orm # sets the parent class of libe file (e.g: `Foo < Sequel::Model` for Sequel)
|
102
103
|
```
|
103
104
|
to add CRUD endpoints for resource foo. By given http methods only this one would be generated.
|
104
105
|
For available methods see: [`Templates::Endpoints`](https://github.com/LeFnord/grape-starter/blob/d7bb6c4946dc27fcafa5a75435b45bfe2b7277f0/lib/starter/builder/templates/endpoints.rb#L7-L26).
|
data/bin/grape-starter
CHANGED
@@ -61,6 +61,8 @@ command :add do |c|
|
|
61
61
|
desc: 'adds entity file'
|
62
62
|
c.switch [:o, :orm], negatable: false,
|
63
63
|
desc: 'inherit from ORM'
|
64
|
+
c.switch [:m, :migration], negatable: false,
|
65
|
+
desc: 'create also migration file'
|
64
66
|
|
65
67
|
c.action do |global_options, options, args|
|
66
68
|
exit_now! 'no resource given' if args.empty?
|
data/lib/starter/builder.rb
CHANGED
@@ -27,6 +27,9 @@ module Starter
|
|
27
27
|
# name - A String as project name
|
28
28
|
# source - A String which provides the template path
|
29
29
|
# destination - A String which provides the new project path
|
30
|
+
# options - A Hash to provide some optional arguments (default: {})
|
31
|
+
# :prefix - Sets the Prefix for the API
|
32
|
+
# :orm - Sets and creates ORM specific files
|
30
33
|
def new!(name, source, destination, options = {})
|
31
34
|
@resource = name
|
32
35
|
@destination = destination
|
@@ -38,29 +41,25 @@ module Starter
|
|
38
41
|
replace_static(File.join(config[:file]), config[:pattern])
|
39
42
|
end
|
40
43
|
|
44
|
+
Starter::Config.save(
|
45
|
+
dest: destination,
|
46
|
+
content: { prefix: prefix, orm: options[:orm].to_s }
|
47
|
+
)
|
48
|
+
|
41
49
|
Orms.build(destination, options[:orm]) if options[:orm]
|
42
|
-
Starter::Config.save(dest: destination, content: { prefix: prefix })
|
43
50
|
|
44
51
|
self
|
45
52
|
end
|
46
53
|
|
47
|
-
def config_static
|
48
|
-
[
|
49
|
-
{ file: %w[script server], pattern: "API-#{resource}" },
|
50
|
-
{ file: %w[api base.rb], pattern: prefix ? "prefix :#{prefix}" : nil },
|
51
|
-
{ file: %w[spec requests root_spec.rb], pattern: prefix ? "/#{prefix}" : nil },
|
52
|
-
{ file: %w[spec requests documentation_spec.rb], pattern: prefix ? "/#{prefix}" : nil }
|
53
|
-
]
|
54
|
-
end
|
55
|
-
|
56
54
|
# would be called from add command
|
57
55
|
#
|
58
56
|
# resource - A String as name
|
59
57
|
# options - A Hash to provide some optional arguments (default: {})
|
60
|
-
#
|
61
|
-
#
|
62
|
-
#
|
63
|
-
#
|
58
|
+
# :set – Whitespace separated list of http verbs
|
59
|
+
# (default: nil, possible: post get put patch delete)
|
60
|
+
# :force - A Boolean, if given existent files should be overwriten (default: false)
|
61
|
+
# :entity - A Boolean, if given an entity file would be created (default: false)
|
62
|
+
# :orm - A Boolean, if given the created lib/model file will be inherited orm specific (default: false)
|
64
63
|
def add!(resource, options = {})
|
65
64
|
@resource = resource
|
66
65
|
@set = options[:set]
|
@@ -68,6 +67,7 @@ module Starter
|
|
68
67
|
@entity = options[:entity]
|
69
68
|
@orm = options[:orm]
|
70
69
|
|
70
|
+
Orms.add_migration(klass_name, resource.downcase) if @orm
|
71
71
|
save_resource
|
72
72
|
end
|
73
73
|
|
@@ -75,7 +75,7 @@ module Starter
|
|
75
75
|
#
|
76
76
|
# resource - A String, which indicates the resource to remove
|
77
77
|
# options - A Hash to provide some optional arguments (default: {})
|
78
|
-
#
|
78
|
+
# :entity - A Boolean, if given an entity file would also be removed (default: nil -> false)
|
79
79
|
def remove!(resource, options = {})
|
80
80
|
@resource = resource
|
81
81
|
@entity = options[:entity]
|
@@ -105,7 +105,18 @@ module Starter
|
|
105
105
|
|
106
106
|
# #new! project creation releated helper methods
|
107
107
|
#
|
108
|
-
#
|
108
|
+
# defines static files to be created
|
109
|
+
def config_static
|
110
|
+
[
|
111
|
+
{ file: %w[script server], pattern: "API-#{resource}" },
|
112
|
+
{ file: %w[api base.rb], pattern: prefix ? "prefix :#{prefix}" : nil },
|
113
|
+
{ file: %w[spec requests root_spec.rb], pattern: prefix ? "/#{prefix}" : nil },
|
114
|
+
{ file: %w[spec requests documentation_spec.rb], pattern: prefix ? "/#{prefix}" : nil }
|
115
|
+
]
|
116
|
+
end
|
117
|
+
|
118
|
+
#
|
119
|
+
# replace something in static files
|
109
120
|
def replace_static(file, replacement)
|
110
121
|
server_file = File.join(destination, file)
|
111
122
|
|
data/lib/starter/builder/orms.rb
CHANGED
@@ -4,18 +4,12 @@ module Starter
|
|
4
4
|
class Orms
|
5
5
|
class << self
|
6
6
|
def build(dest, orm)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
extend(::Starter::Templates::Sequel)
|
12
|
-
when 'activerecord', 'ar'
|
13
|
-
require 'starter/builder/templates/activerecord'
|
14
|
-
extend(::Starter::Templates::ActiveRecord)
|
7
|
+
load_orm(orm: orm)
|
8
|
+
return if @orm.nil?
|
9
|
+
|
10
|
+
if @orm == 'ar' || @orm == 'activerecord'
|
15
11
|
# Fixes pooling
|
16
12
|
add_middleware(dest, 'ActiveRecord::Rack::ConnectionManagement')
|
17
|
-
else
|
18
|
-
return
|
19
13
|
end
|
20
14
|
|
21
15
|
build_initializer(File.join(dest, 'config', 'initializers'))
|
@@ -23,8 +17,6 @@ module Starter
|
|
23
17
|
append_to_file(File.join(dest, 'Rakefile'), rakefile)
|
24
18
|
append_to_file(File.join(dest, 'Gemfile'), gemfile)
|
25
19
|
prepare_for_migrations(File.join(dest, 'db'))
|
26
|
-
|
27
|
-
Starter::Config.save(dest: dest, content: { orm: orm.downcase })
|
28
20
|
end
|
29
21
|
|
30
22
|
def config
|
@@ -56,6 +48,30 @@ module Starter
|
|
56
48
|
FILE
|
57
49
|
end
|
58
50
|
|
51
|
+
def add_migration(klass_name, resource)
|
52
|
+
load_orm
|
53
|
+
return if @orm.nil?
|
54
|
+
|
55
|
+
file_name = "#{Time.now.strftime('%Y%m%d%H%m%S')}_Create#{klass_name}.rb"
|
56
|
+
migration_dest = File.join(Dir.pwd, 'db', 'migrations', file_name)
|
57
|
+
FileFoo.write_file(migration_dest, migration(klass_name, resource))
|
58
|
+
end
|
59
|
+
|
60
|
+
def load_orm(orm: ::Starter::Config.read[:orm])
|
61
|
+
@orm = orm
|
62
|
+
|
63
|
+
case @orm
|
64
|
+
when 'sequel'
|
65
|
+
require 'starter/builder/templates/sequel'
|
66
|
+
extend(::Starter::Templates::Sequel)
|
67
|
+
when 'activerecord', 'ar'
|
68
|
+
require 'starter/builder/templates/activerecord'
|
69
|
+
extend(::Starter::Templates::ActiveRecord)
|
70
|
+
else
|
71
|
+
@orm = nil
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
59
75
|
private
|
60
76
|
|
61
77
|
def adapter
|
@@ -86,6 +86,19 @@ module Starter
|
|
86
86
|
gem 'sqlite3'
|
87
87
|
FILE
|
88
88
|
end
|
89
|
+
|
90
|
+
def migration(klass_name, resource)
|
91
|
+
<<-FILE.strip_heredoc
|
92
|
+
class Create#{klass_name} < ActiveRecord::Migration[5.1]
|
93
|
+
def change
|
94
|
+
create_table :#{resource} do |t|
|
95
|
+
|
96
|
+
t.timestamps
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
FILE
|
101
|
+
end
|
89
102
|
end
|
90
103
|
end
|
91
104
|
end
|
@@ -86,6 +86,21 @@ module Starter
|
|
86
86
|
gem 'sqlite3'
|
87
87
|
FILE
|
88
88
|
end
|
89
|
+
|
90
|
+
def migration(_klass_name, resource)
|
91
|
+
<<-FILE.strip_heredoc
|
92
|
+
Sequel.migration do
|
93
|
+
change do
|
94
|
+
create_table :#{resource} do
|
95
|
+
primary_key :id
|
96
|
+
|
97
|
+
DateTime :created_at
|
98
|
+
DateTime :updated_at
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
FILE
|
103
|
+
end
|
89
104
|
end
|
90
105
|
end
|
91
106
|
end
|
data/lib/starter/version.rb
CHANGED
data/template/Gemfile
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: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LeFnord
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|
@@ -76,6 +76,7 @@ extra_rdoc_files: []
|
|
76
76
|
files:
|
77
77
|
- ".gitignore"
|
78
78
|
- ".inch.yml"
|
79
|
+
- ".rspec"
|
79
80
|
- ".rubocop.yml"
|
80
81
|
- ".rubocop_todo.yml"
|
81
82
|
- ".travis.yml"
|