grape-starter 0.3.0 → 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 +4 -4
- data/README.md +10 -3
- data/bin/grape-starter +17 -16
- data/doc/re-doc.png +0 -0
- data/lib/starter/builder.rb +58 -23
- data/lib/starter/version.rb +1 -1
- data/template/script/server +8 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ca5b09c3e3577d7a93143d6fff88b91aecfd926
|
4
|
+
data.tar.gz: 8cd9948d9aa98b6c12cd118cca08d3d1858ad62f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22665163096ced52badfbdd0b99e2373108f18c0a6ae68002bad33d525b75b408d807fd9cca10c91dd49631fbef466d85c69bd9a72f39fddabd32b022ad00490
|
7
|
+
data.tar.gz: 83e99286b0d75e30ea70b80f7430918179178982c5dd4ea1958ce9632cd20c13ee6262f908ab742cea05b9d3778344c6723e84d69560164bf9761f2f8ce7c9d8
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[](https://travis-ci.org/LeFnord/grape-starter)
|
2
2
|
[](https://badge.fury.io/rb/grape-starter)
|
3
3
|
[](http://inch-ci.org/github/LeFnord/grape-starter)
|
4
4
|
|
@@ -8,6 +8,7 @@
|
|
8
8
|
Is a tool to help you to build up a skeleton for a [Grape](http://github.com/ruby-grape/grape) API mounted on [Rack](https://github.com/rack/rack) ready to run.
|
9
9
|
[grape-swagger](http://github.com/ruby-grape/grape-swagger) would be used to generate a [OAPI](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) compatible documentation, which could be shown with [ReDoc](https://github.com/Rebilly/ReDoc).
|
10
10
|
|
11
|
+

|
11
12
|
|
12
13
|
## Why the next one?
|
13
14
|
|
@@ -56,9 +57,10 @@ This command creates a folder named `awesome_api` containing the skeleton. With
|
|
56
57
|
To run it, go into awesome_api folder, start the server
|
57
58
|
```
|
58
59
|
$ cd awesome_api
|
59
|
-
$ ./script/server
|
60
|
+
$ ./script/server *port
|
60
61
|
```
|
61
|
-
the API is now accessible under: [http://localhost:9292/api/v1/root](http://localhost:9292/api/v1/root)
|
62
|
+
the API is now accessible under: [http://localhost:9292/api/v1/root](http://localhost:9292/api/v1/root)
|
63
|
+
the documentation of it under: [http://localhost:9292/](http://localhost:9292/)
|
62
64
|
|
63
65
|
More could be found in [README](template/README.md).
|
64
66
|
|
@@ -87,3 +89,8 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/LeFnor
|
|
87
89
|
## License
|
88
90
|
|
89
91
|
The gem is available as open source under the terms of the [MIT License](LICENSE).
|
92
|
+
|
93
|
+
### ToDos
|
94
|
+
|
95
|
+
- [x] make scripts more configurable
|
96
|
+
- [ ] add logging
|
data/bin/grape-starter
CHANGED
@@ -25,25 +25,26 @@ arg_name 'project name'
|
|
25
25
|
command :new do |c|
|
26
26
|
|
27
27
|
c.action do |global_options, _, args|
|
28
|
-
|
28
|
+
dest = args.empty? ? nil : File.join(Dir.getwd, args.first)
|
29
29
|
|
30
30
|
case
|
31
|
-
when args.empty? ||
|
32
|
-
exit_now! 'no name given: starter new project'
|
33
|
-
when Dir.exist?(
|
31
|
+
when args.empty? || dest.nil?
|
32
|
+
exit_now! 'no name given: grape-starter new project'
|
33
|
+
when Dir.exist?(dest) && !global_options[:force]
|
34
34
|
exit_now! 'project exist: -f to overwrite'
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
35
|
+
else
|
36
|
+
starter_gem = Gem::Specification.find_by_name('grape-starter').gem_dir
|
37
|
+
src = File.join(starter_gem, 'template', '.')
|
38
|
+
|
39
|
+
Starter::Builder.new!(args.first, src, dest)
|
40
|
+
$stdout.puts "created: #{args.first}"
|
41
|
+
|
42
|
+
# after creating tasks
|
43
|
+
FileUtils.cd(dest) do
|
44
|
+
$stdout.puts `bundle install`
|
45
|
+
$stdout.puts `bundle exec rubocop -a`
|
46
|
+
$stdout.puts `git init`
|
47
|
+
end
|
47
48
|
end
|
48
49
|
end
|
49
50
|
end
|
data/doc/re-doc.png
ADDED
Binary file
|
data/lib/starter/builder.rb
CHANGED
@@ -12,15 +12,34 @@ module Starter
|
|
12
12
|
extend Template::Endpoints
|
13
13
|
|
14
14
|
class << self
|
15
|
-
attr_reader :resource, :set, :force, :entity
|
15
|
+
attr_reader :resource, :set, :force, :entity, :destination
|
16
|
+
|
17
|
+
# would be called on new command
|
18
|
+
# it should do following
|
19
|
+
# 1. copying the template to the new destination
|
20
|
+
# 2. replace names in …
|
21
|
+
# - script/server
|
22
|
+
#
|
23
|
+
# name - A String as project name
|
24
|
+
# source - A String which provides the template path
|
25
|
+
# destination - A String which provides the new project path
|
26
|
+
def new!(name, source, destination)
|
27
|
+
@resource = name
|
28
|
+
@destination = destination
|
29
|
+
|
30
|
+
FileUtils.copy_entry source, destination
|
31
|
+
|
32
|
+
replace_static(File.join('script','server'))
|
33
|
+
end
|
34
|
+
|
16
35
|
# would be called on add command
|
17
36
|
#
|
18
37
|
# resource - A String as name
|
19
38
|
# options - A Hash to provide some optional arguments (default: {})
|
20
39
|
# :set – whitespace separated list of http verbs
|
21
|
-
# (default: nil, possible: post
|
22
|
-
# :force - A Boolean, if given existent files should be overwriten (default:
|
23
|
-
# :entity - A Boolean, if given an entity file would be created (default:
|
40
|
+
# (default: nil, possible: post get put patch delete)
|
41
|
+
# :force - A Boolean, if given existent files should be overwriten (default: false)
|
42
|
+
# :entity - A Boolean, if given an entity file would be created (default: false)
|
24
43
|
def add!(resource, options = {})
|
25
44
|
@resource = resource
|
26
45
|
@set = options[:set]
|
@@ -30,7 +49,6 @@ module Starter
|
|
30
49
|
self
|
31
50
|
end
|
32
51
|
|
33
|
-
# would also be called on add command,
|
34
52
|
# it saves the files
|
35
53
|
def save
|
36
54
|
created_files = file_list.each_with_object([]) do |new_file, memo|
|
@@ -63,7 +81,7 @@ module Starter
|
|
63
81
|
remove_mount_point
|
64
82
|
end
|
65
83
|
|
66
|
-
# provides the endpoints for
|
84
|
+
# provides the endpoints for the given resource
|
67
85
|
def endpoints
|
68
86
|
content(endpoint_set).join("\n\n")
|
69
87
|
end
|
@@ -75,26 +93,45 @@ module Starter
|
|
75
93
|
|
76
94
|
private
|
77
95
|
|
96
|
+
# provides an array of endpoints to for the new resource
|
97
|
+
def endpoint_set
|
98
|
+
crud_set = singular? ? singular_one : crud
|
99
|
+
return crud_set if set.blank?
|
100
|
+
|
101
|
+
crud_set.each_with_object([]) { |x, memo| set.map { |y| memo << x if x.to_s.start_with?(y) } }
|
102
|
+
end
|
103
|
+
|
104
|
+
# provides a file list for the new resource
|
78
105
|
def file_list
|
79
106
|
standards = %w(api_file lib_file api_spec lib_spec)
|
80
107
|
|
81
108
|
entity ? standards + ['entity_file'] : standards
|
82
109
|
end
|
83
110
|
|
111
|
+
# raises if resource exist and force == false
|
84
112
|
def should_raise?(file)
|
85
113
|
raise StandardError, '… resource exists' if File.exist?(file) && !force
|
86
114
|
end
|
87
115
|
|
116
|
+
# add project name to static files
|
117
|
+
def replace_static(file)
|
118
|
+
server_file = File.join(destination, file)
|
119
|
+
|
120
|
+
file_foo(server_file) { |content| content.gsub!('{{{grape-starter}}}', "API-#{resource}") }
|
121
|
+
end
|
122
|
+
|
88
123
|
def add_mount_point
|
89
|
-
|
90
|
-
add_to_base(file)
|
91
|
-
write_file(api_base_file_name, file)
|
124
|
+
file_foo(api_base_file_name) { |content| add_to_base(content) }
|
92
125
|
end
|
93
126
|
|
94
127
|
def remove_mount_point
|
95
|
-
|
96
|
-
|
97
|
-
|
128
|
+
file_foo(api_base_file_name) { |content| remove_from_base(content) }
|
129
|
+
end
|
130
|
+
|
131
|
+
def file_foo(file)
|
132
|
+
content = read_file(file)
|
133
|
+
yield content
|
134
|
+
write_file(file, content)
|
98
135
|
end
|
99
136
|
|
100
137
|
def save_file(new_file)
|
@@ -103,13 +140,6 @@ module Starter
|
|
103
140
|
write_file(send(new_file_name), send(new_file.strip_heredoc))
|
104
141
|
end
|
105
142
|
|
106
|
-
def endpoint_set
|
107
|
-
crud_set = singular? ? singular_one : crud
|
108
|
-
return crud_set if set.blank?
|
109
|
-
|
110
|
-
crud_set.each_with_object([]) { |x, memo| set.map { |y| memo << x if x.to_s.start_with?(y) } }
|
111
|
-
end
|
112
|
-
|
113
143
|
# manipulating API Base file
|
114
144
|
# … adding
|
115
145
|
def add_to_base(file)
|
@@ -123,17 +153,22 @@ module Starter
|
|
123
153
|
file.sub!(mount_point, '')
|
124
154
|
end
|
125
155
|
|
156
|
+
# content of the given set of files,
|
157
|
+
# returns an array of string
|
158
|
+
def content(set)
|
159
|
+
set.map { |x| send(x) }
|
160
|
+
end
|
161
|
+
|
162
|
+
# general file
|
163
|
+
# … read
|
126
164
|
def read_file(file)
|
127
165
|
File.read(file)
|
128
166
|
end
|
129
167
|
|
168
|
+
# … write
|
130
169
|
def write_file(file, content)
|
131
170
|
File.open(file, 'w') { |f| f.write(content) }
|
132
171
|
end
|
133
|
-
|
134
|
-
def content(set)
|
135
|
-
set.map { |x| send(x) }
|
136
|
-
end
|
137
172
|
end
|
138
173
|
end
|
139
174
|
end
|
data/lib/starter/version.rb
CHANGED
data/template/script/server
CHANGED
@@ -7,8 +7,14 @@ cd "$(dirname "$0")/.."
|
|
7
7
|
test -z "$RACK_ENV" &&
|
8
8
|
RACK_ENV='development'
|
9
9
|
|
10
|
+
if [ $1 ]; then
|
11
|
+
port=$1
|
12
|
+
else
|
13
|
+
port=9292
|
14
|
+
fi
|
15
|
+
|
10
16
|
if [ "$RACK_ENV" = 'production' ]; then
|
11
|
-
bundle exec thin start -p
|
17
|
+
bundle exec thin start -p $port -e $RACK_ENV --tag {{{grape-starter}}} -d --threaded
|
12
18
|
else
|
13
|
-
bundle exec thin start -p
|
19
|
+
bundle exec thin start -p $port -e $RACK_ENV --tag {{{grape-starter}}} -V -D
|
14
20
|
fi
|
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LeFnord
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|
@@ -156,6 +156,7 @@ files:
|
|
156
156
|
- README.md
|
157
157
|
- Rakefile
|
158
158
|
- bin/grape-starter
|
159
|
+
- doc/re-doc.png
|
159
160
|
- grape-starter.gemspec
|
160
161
|
- lib/starter.rb
|
161
162
|
- lib/starter/builder.rb
|