grape-starter 0.6.2 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b471f4f46d1cb6c4969df938735df13056480499
4
- data.tar.gz: 9012698a82c22802fa0220ba6cae54f9eda8ad16
3
+ metadata.gz: 6ce54496d2a64c456a6d1e1a677478fe0bed3067
4
+ data.tar.gz: 853b3d32ba5bd42c64bafaee58ad03fef82fb67f
5
5
  SHA512:
6
- metadata.gz: b74bfeb4d8fc482ae4807c35948ce209843c8f2f237d49ddeedd96bf42c2e4a75e511fcf465ee1f00f13ae34c724c7a2ba7b03c5c2ce194b93f4e4acdc85f45f
7
- data.tar.gz: fe9a8707f9fe421061a9af064d09eb49601925a771e636b0cae2465bc34fac4e9c1a8e48779f4b56ce76bbab5d7f96c3805cbba801b1368d60f96e392dbf5ff2
6
+ metadata.gz: 5d1210d3be1e31da4a12aaf49a536c49bc6f6fcbbcdd06f6831690048428427745f4d82918f821467041c7b6895119df9166d7fc323605c666df28178697a96f
7
+ data.tar.gz: d1beec85ca244b47041ff421c96acd47c55db2a154d82ba09dc4e0c9a1f4eddb64bd67bdf135a2627e96e6fa8994aaefbad5f2f395b34ba1560b454516dc7ca2
data/.inch.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  files:
2
2
  excluded:
3
- - lib/starter/builder/template_endpoints.rb
4
- - lib/starter/builder/template_files.rb
3
+ - lib/starter/builder/templates/endpoints.rb
4
+ - lib/starter/builder/templates/files.rb
5
+ - lib/starter/builder/templates/sequel.rb
5
6
  - lib/starter/builder/names.rb
6
7
  - lib/starter/rake/grape_tasks.rb
@@ -8,7 +8,7 @@ AllCops:
8
8
  - '**/template/**/*'
9
9
  - grape-starter.gemspec
10
10
  UseCache: true
11
- TargetRubyVersion: 2.3
11
+ TargetRubyVersion: 2.4
12
12
 
13
13
  Metrics/BlockLength:
14
14
  Exclude:
@@ -19,16 +19,16 @@ Metrics/LineLength:
19
19
 
20
20
  Style/AccessorMethodName:
21
21
  Exclude:
22
- - 'lib/starter/builder/template_files.rb'
23
- - 'lib/starter/builder/template_endpoints.rb'
22
+ - 'lib/starter/builder/templates/files.rb'
23
+ - 'lib/starter/builder/templates/endpoints.rb'
24
24
 
25
25
  Style/AsciiComments:
26
26
  Enabled: false
27
27
 
28
28
  Style/IndentationWidth:
29
29
  Exclude:
30
- - 'lib/starter/builder/template_files.rb'
31
- - 'lib/starter/builder/template_endpoints.rb'
30
+ - 'lib/starter/builder/templates/files.rb'
31
+ - 'lib/starter/builder/templates/endpoints.rb'
32
32
 
33
33
  Style/Documentation:
34
34
  Exclude:
@@ -6,7 +6,8 @@
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 1
10
- # Configuration parameters: CountComments.
9
+ Metrics/AbcSize:
10
+ Max: 20
11
+
11
12
  Metrics/MethodLength:
12
13
  Max: 20
@@ -1,5 +1,18 @@
1
1
  ### NEXT
2
2
 
3
+ - contributions
4
+
5
+ ### 0.7.0
6
+
7
+ - [212e6…](https://github.com/LeFnord/grape-starter/commit/212e6245e10598efe286143dac39f46134c58c54) - makes mounting of doc more secure
8
+ - [f3bb6…](https://github.com/LeFnord/grape-starter/commit/f3bb63fdee79df4552316524b1ac3adaebab811a) - adds orm option so that the `add` resource command can optional use configured ORM
9
+ - [af138…](https://github.com/LeFnord/grape-starter/commit/af1388ae6479b81646c56ac55f856ea275dc9817) - resource respects configured orm
10
+ - [5ac74…](https://github.com/LeFnord/grape-starter/commit/5ac747a7fb44d97eedbeba1e7a11e475846d7743) - improve README
11
+ - [eb33c…](https://github.com/LeFnord/grape-starter/commit/eb33c910c623b34db54ccb64ee59af4c639029e4) - adds base storing of configuration
12
+ - [751aa…](https://github.com/LeFnord/grape-starter/commit/751aa8ae929bed0ff66ac9830468279238bec252) - adding option to add Sequel support
13
+ - [354e6…](https://github.com/LeFnord/grape-starter/commit/354e63abd77751fe0f3a1b405bb49ab754ab1522) - re-organizing of template files
14
+ - [6e33e…](https://github.com/LeFnord/grape-starter/commit/6e33e8137aa293eef66913c50010c53d284a0d8d) - Add awesome_print dependency ([@terry90](https://github.com/terry90))
15
+
3
16
  ### 0.6.0
4
17
 
5
18
  **breaking changes** renames all api stuff under lib to models (includes, of course, the namespace):
data/README.md CHANGED
@@ -12,9 +12,8 @@ Is a tool to help you to build up a skeleton for a [Grape](http://github.com/rub
12
12
 
13
13
  ## Why the next one?
14
14
 
15
- - build up a playground for your ideas, prototypes, testing behaviour, whatever
16
- (I use it to implement specific behaviour and get specs of for [grape-swagger](http://github.com/ruby-grape/grape-swagger))
17
- - no assumtions about a backend/ORM, ergo no restrictions, only a pure grape/rack skeleton
15
+ - build up a playground for your ideas, prototypes, testing behaviour whatever
16
+ - ~~no assumtions about~~ you can choose, if you want to use a backend/ORM, ergo no restrictions, only a pure grape/rack skeleton with a nice documentation
18
17
 
19
18
  ## Usage
20
19
 
@@ -28,6 +27,12 @@ $ gem install grape-starter
28
27
  ```
29
28
  $ grape-starter new awesome_api
30
29
  ```
30
+ with following options:
31
+ ```
32
+ -f, --force # overwrites existend project
33
+ -p foobar, --prefix=foobar # provide a prefix under which the API can be accessed, default: api
34
+ -o sequel, --orm=sequel # create also needed files and folders for the specified ORM
35
+ ```
31
36
 
32
37
  This command creates a folder named `awesome_api` containing the skeleton. With following structure:
33
38
 
@@ -36,16 +41,16 @@ This command creates a folder named `awesome_api` containing the skeleton. With
36
41
  ├── api
37
42
  │   ├── base.rb # the main API class, all other endpoints would be mounted in it
38
43
  │   ├── endpoints # contains the endpoint file for a resource
39
- │   │   └── root.rb # root is always available, it exposes all routes/endpoints, disable by comment out in base.rb
44
+ │   │   └── root.rb # root is always available, it exposes all routes/endpoints, disable by comment it out in base.rb
40
45
  │   └── entities # contains the entity representation of the reource, if wanted
41
46
  │   └── route.rb
42
47
  ├── config # base configuration
43
48
  │   └── …
44
49
  ├── config.ru # Rack it up
45
50
  ├── lib # contains the additional lib file for a resource
46
- │   ├── api
51
+ │   ├── models
47
52
  │   │   └── version.rb
48
- │   └── api.rb
53
+ │   └── models.rb
49
54
  ├── public # for serving static files
50
55
  │   └── redoc.html # provides the ReDoc generated oapi documentation
51
56
  ├── script # setup / server / test etc.
@@ -54,25 +59,63 @@ This command creates a folder named `awesome_api` containing the skeleton. With
54
59
     └── …
55
60
  ```
56
61
 
62
+ … using `--orm` flag adds follwing files and directories to above project structure:
63
+ ```
64
+ ├── .config
65
+ ├── config
66
+ │   …
67
+ │   ├── database.yml
68
+ │   └── initializers
69
+ │   └── database.rb
70
+
71
+ ├── db
72
+ │   └── migrations
73
+
74
+ ```
75
+
76
+ Don't forget to adapt the `config/database.yml` to your needs
77
+ and also to check the Gemfile for the right gems.
78
+
79
+ In `.config` the choosen ORM would be stored.
80
+
57
81
  To run it, go into awesome_api folder, start the server
58
82
  ```
59
83
  $ cd awesome_api
60
84
  $ ./script/server *port
61
85
  ```
62
86
  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/).
87
+ the documentation of it under: [http://localhost:9292/doc](http://localhost:9292/doc).
64
88
 
65
89
  More could be found in [README](template/README.md).
66
90
 
67
91
 
68
92
  #### Add resources
69
93
  ```
70
- $ grape-starter add foo
94
+ $ grape-starter add foo [http methods]
71
95
  ```
72
- to add CRUD endpoints for resource foo. For more options, see `grape-starter add -h`.
73
-
74
96
  This adds endpoint and lib file and belonging specs, and a mount entry in base.rb.
75
97
 
98
+ Using it with following options:
99
+ ```
100
+ -e, --entity # a grape entity file will also be created
101
+ -o, --orm # sets the parent class of libe file (e.g: `Foo < Sequel::Model` for Sequel)
102
+ ```
103
+ to add CRUD endpoints for resource foo. By given http methods only this one would be generated.
104
+ For available methods see: [`Templates::Endpoints`](https://github.com/LeFnord/grape-starter/blob/d7bb6c4946dc27fcafa5a75435b45bfe2b7277f0/lib/starter/builder/templates/endpoints.rb#L7-L26).
105
+
106
+ Example:
107
+ ```
108
+ grape-starter add foo post get
109
+ ```
110
+ will use `post` and `get_one` to create the `post` and `get` endpoint, it would be respected, if it is the singular or plural form of it, so the plural form would look like:
111
+ ```
112
+ grape-starter add foos post get
113
+ ```
114
+ this will use `post`, `get_all` and `get_specific` to create the `post`, `get` and `get :id` endpoints.
115
+
116
+ If the `orm` switch `true`, the lib class would be created as child class of a specific ORM class,
117
+ so for example for Sequel, it would be wirtten: `Foo < Sequel::Model` instead of `Foo`, hereby the using ORM would be taken from the configuration, which was stored by project creation.
118
+
76
119
 
77
120
  #### Remove a resource
78
121
  ```
@@ -83,14 +126,48 @@ to remove previous generated files for a resource.
83
126
 
84
127
  ## Contributing
85
128
 
86
- Bug reports and pull requests are welcome on GitHub at https://github.com/LeFnord/grape-starter.
129
+ Any contributions are welcome on GitHub at https://github.com/LeFnord/grape-starter.
87
130
 
131
+ ### Adding a new ORM template
88
132
 
89
- ## License
133
+ To add an new ORM, it needs following steps:
90
134
 
91
- The gem is available as open source under the terms of the [MIT License](LICENSE).
135
+ 1. A template class, with predefined methods
136
+
137
+ ```ruby
138
+ module Starter
139
+ module Templates
140
+ module <YOUR NAME>
141
+ def model_klass
142
+ # the class, from which self inherit, e.g. 'Sequel::Model'
143
+ end
144
+
145
+ def initializer
146
+ # provide your string
147
+ end
92
148
 
93
- ### ToDos
149
+ def config
150
+ # provide your string
151
+ end
94
152
 
95
- - [ ] make usage of [grape_oauth2](https://github.com/nbulaj/grape_oauth2) available
96
- - usage of Rack middleware as plug-in system
153
+ def rakefile
154
+ # provide your string
155
+ end
156
+
157
+ def gemfile
158
+ # provide your string
159
+ end
160
+ end
161
+ end
162
+ end
163
+ ```
164
+
165
+ see as example [sequel.rb](lib/starter/builder/templates/sequel.rb), there the return value of each method would be written into the
166
+ corresponding file (see: [orms.rb](lib/starter/builder/orms.rb)).
167
+
168
+ 2. An additional switch in the [`Starter::Orms.build`](https://github.com/LeFnord/grape-starter/blob/67738438ba9278b280a6eac402096fcb74526ab3/lib/starter/builder/orms.rb#L7-L13) method to choose the template.
169
+ 3. An entry in the description of the [`add` command](https://github.com/LeFnord/grape-starter/blob/master/bin/grape-starter#L30), when it would be called with `-h`
170
+
171
+ ## License
172
+
173
+ The gem is available as open source under the terms of the [MIT License](LICENSE).
@@ -25,6 +25,9 @@ command :new do |c|
25
25
  c.flag [:p, :prefix],
26
26
  default_value: 'api',
27
27
  desc: 'sets the prefix of the API'
28
+ c.flag [:o, :orm],
29
+ default_value: 'sequel',
30
+ desc: 'prepares for the given ORM (Sequel, …)'
28
31
 
29
32
  c.action do |global_options, options, args|
30
33
  dest = args.empty? ? nil : File.join(Dir.getwd, args.first)
@@ -38,14 +41,14 @@ command :new do |c|
38
41
  starter_gem = Gem::Specification.find_by_name('grape-starter').gem_dir
39
42
  src = File.join(starter_gem, 'template', '.')
40
43
 
41
- Starter::Builder.new!(args.first, src, dest, options[:p])
44
+ Starter::Builder.new!(args.first, src, dest, options)
42
45
  $stdout.puts "created: #{args.first}"
43
46
 
44
47
  # after creating tasks
45
48
  FileUtils.cd(dest) do
46
- $stdout.puts `bundle install`
47
- $stdout.puts `bundle exec rubocop -a`
48
- $stdout.puts `git init; git add .; git commit -m 'initial commit'`
49
+ system('bundle install')
50
+ `bundle exec rubocop -a`
51
+ system("git init; git add .; git commit -m 'initial commit'")
49
52
  end
50
53
  end
51
54
  end
@@ -56,8 +59,10 @@ long_desc "Adds given resource, hereby the numerus of the provided
56
59
  resource would be respected to create singular or plural endpoints"
57
60
  arg_name 'resource [post* get* put* patch* delete*]'
58
61
  command :add do |c|
59
- c.desc 'adds entity file'
60
- c.switch [:e, :entity], negatable: false
62
+ c.switch [:e, :entity], negatable: false,
63
+ desc: 'adds entity file'
64
+ c.switch [:o, :orm], negatable: false,
65
+ desc: 'inherit from ORM'
61
66
 
62
67
  c.action do |global_options, options, args|
63
68
  exit_now! 'no resource given' if args.empty?
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.required_ruby_version = '>= 2.2.6'
26
26
 
27
27
  spec.add_dependency 'gli', '~> 2.16'
28
- spec.add_dependency 'activesupport', '~> 5.0'
29
- spec.add_dependency 'rubocop', '~> 0.48'
28
+ spec.add_dependency 'activesupport', '~> 5.1'
29
+ spec.add_dependency 'rubocop', '~> 0.49'
30
30
  spec.add_dependency 'awesome_print', '~> 1.7'
31
31
  end
@@ -4,6 +4,7 @@ require 'awesome_print'
4
4
 
5
5
  require 'starter/version'
6
6
  require 'starter/builder'
7
+ require 'starter/config'
7
8
 
8
9
  module Starter
9
10
  autoload :Rake, 'starter/rake/grape_tasks'
@@ -3,20 +3,21 @@
3
3
  require 'active_support/core_ext/string'
4
4
 
5
5
  module Starter
6
+ require 'starter/builder/orms'
6
7
  require 'starter/builder/names'
7
8
  require 'starter/builder/base_file'
8
9
  require 'starter/builder/file_foo'
9
- require 'starter/builder/template_files'
10
- require 'starter/builder/template_endpoints'
10
+ require 'starter/builder/templates/files'
11
+ require 'starter/builder/templates/endpoints'
11
12
 
12
13
  class Builder
13
- extend Starter::Names
14
- extend Starter::BaseFile
15
- extend Template::Files
16
- extend Template::Endpoints
14
+ extend Names
15
+ extend BaseFile
16
+ extend Templates::Files
17
+ extend Templates::Endpoints
17
18
 
18
19
  class << self
19
- attr_reader :prefix, :resource, :set, :force, :entity, :destination
20
+ attr_reader :prefix, :resource, :set, :force, :entity, :destination, :orm
20
21
  #
21
22
  # public methods
22
23
  #
@@ -26,8 +27,8 @@ module Starter
26
27
  # name - A String as project name
27
28
  # source - A String which provides the template path
28
29
  # destination - A String which provides the new project path
29
- def new!(name, source, destination, prefix = 'api')
30
- @prefix = prefix
30
+ def new!(name, source, destination, options = {})
31
+ @prefix = options[:p] || 'api'
31
32
  @resource = name
32
33
  @destination = destination
33
34
 
@@ -38,6 +39,7 @@ module Starter
38
39
  replace_static(File.join('spec', 'requests', 'root_spec.rb'), prefix)
39
40
  replace_static(File.join('spec', 'requests', 'documentation_spec.rb'), prefix)
40
41
 
42
+ Orms.build(destination, options[:orm]) if options[:orm]
41
43
  self
42
44
  end
43
45
 
@@ -54,6 +56,7 @@ module Starter
54
56
  @set = options[:set]
55
57
  @force = options[:force]
56
58
  @entity = options[:entity]
59
+ @orm = options[:orm]
57
60
 
58
61
  save_resource
59
62
  end
@@ -110,7 +113,7 @@ module Starter
110
113
  end
111
114
 
112
115
  #
113
- # saves all resource related files the files
116
+ # saves all resource related files
114
117
  def save_resource
115
118
  created_files = file_list.each_with_object([]) do |new_file, memo|
116
119
  memo << send("#{new_file}_name")
@@ -19,7 +19,7 @@ module Starter
19
19
  FileFoo.call!(api_base_file_name) { |content| remove_from_base(content) }
20
20
  end
21
21
 
22
- # removes mount point form base class
22
+ # removes mount point from base class
23
23
  def remove_from_base(file)
24
24
  file.sub!(mount_point, '')
25
25
  end
@@ -7,6 +7,19 @@ module Starter
7
7
  singular? ? for_klass.classify : for_klass.classify.pluralize
8
8
  end
9
9
 
10
+ def lib_klass_name
11
+ return klass_name unless @orm
12
+
13
+ case ::Starter::Config.read[:orm]
14
+ when 'sequel'
15
+ require 'starter/builder/templates/sequel'
16
+ extend(::Starter::Templates::Sequel)
17
+ "#{klass_name} < #{model_klass}"
18
+ else
19
+ klass_name
20
+ end
21
+ end
22
+
10
23
  def base_file_name
11
24
  @resource.tr('/', '-').downcase + '.rb'
12
25
  end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Starter
4
+ class Orms
5
+ class << self
6
+ def build(dest, orm)
7
+ case orm
8
+ when 'sequel'
9
+ require 'starter/builder/templates/sequel'
10
+ extend(::Starter::Templates::Sequel)
11
+ else
12
+ return
13
+ end
14
+
15
+ build_initializer(File.join(dest, 'config', 'initializers'))
16
+ build_config(File.join(dest, 'config'))
17
+ append_to_file(File.join(dest, 'Rakefile'), rakefile)
18
+ append_to_file(File.join(dest, 'Gemfile'), gemfile)
19
+ prepare_for_migrations(File.join(dest, 'db'))
20
+ Starter::Config.save(dest: dest, content: { orm: orm })
21
+ end
22
+
23
+ private
24
+
25
+ def build_initializer(dest)
26
+ FileUtils.mkdir_p(dest)
27
+ FileFoo.write_file(File.join(dest, 'database.rb'), initializer)
28
+ end
29
+
30
+ def build_config(dest)
31
+ FileFoo.write_file(File.join(dest, 'database.yml'), config)
32
+ end
33
+
34
+ def append_to_file(file_name, content)
35
+ original = FileFoo.read_file(file_name)
36
+ FileFoo.write_file(file_name, "#{original}\n\n#{content}")
37
+ end
38
+
39
+ def prepare_for_migrations(dest)
40
+ migrations = File.join(dest, 'migrations')
41
+ FileUtils.mkdir_p(migrations)
42
+ `touch #{migrations}/.keep`
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Starter
4
- module Template
4
+ module Templates
5
5
  # defining the endpoints -> http methods of a resource
6
6
  module Endpoints
7
7
  def crud
@@ -3,7 +3,7 @@
3
3
  require 'active_support/core_ext/string'
4
4
 
5
5
  module Starter
6
- module Template
6
+ module Templates
7
7
  module Files
8
8
  # API template for resource
9
9
  def api_file
@@ -41,7 +41,7 @@ module Starter
41
41
  # frozen_string_literal: true
42
42
 
43
43
  module Models
44
- class #{klass_name}
44
+ class #{lib_klass_name}
45
45
  end
46
46
  end
47
47
  FILE
@@ -50,9 +50,10 @@ module Starter
50
50
  def api_spec
51
51
  <<-FILE.strip_heredoc
52
52
  # frozen_string_literal: true
53
+
53
54
  require 'spec_helper'
54
55
 
55
- RSpec.describe '/#{base_prefix}/#{base_version}/#{resource}' do
56
+ RSpec.describe '/#{base_prefix}/#{base_version}/#{resource.downcase}' do
56
57
  #{endpoint_specs}
57
58
  end
58
59
  FILE
@@ -61,6 +62,7 @@ module Starter
61
62
  def lib_spec
62
63
  <<-FILE.strip_heredoc
63
64
  # frozen_string_literal: true
65
+
64
66
  require 'spec_helper'
65
67
 
66
68
  RSpec.describe Models::#{klass_name} do
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Starter
4
+ module Templates
5
+ module Sequel
6
+ def model_klass
7
+ 'Sequel::Model'
8
+ end
9
+
10
+ def initializer
11
+ <<-FILE.strip_heredoc
12
+ # frozen_string_literal: true
13
+
14
+ require 'yaml'
15
+
16
+ # load Sequel Configuration
17
+ settings = YAML.load_file('config/database.yml')
18
+ DB = Sequel.connect(settings[ENV['RACK_ENV']])
19
+ FILE
20
+ end
21
+
22
+ def config
23
+ <<-FILE.strip_heredoc
24
+ # Sequel Database Configuration
25
+ development:
26
+ adapter: 'sqlite'
27
+ host: localhost
28
+ port: 27017
29
+ database: "db/development.sqlite3"
30
+ username:
31
+ password:
32
+
33
+ test:
34
+ adapter: 'sqlite'
35
+ host: localhost
36
+ port: 27017
37
+ database: "db/test.sqlite3"
38
+ username:
39
+ password:
40
+
41
+ production:
42
+ adapter: 'sqlite'
43
+ host: localhost
44
+ port: 27017
45
+ database: "db/production.sqlite3"
46
+ username:
47
+ password:
48
+ FILE
49
+ end
50
+
51
+ def rakefile
52
+ <<-FILE.strip_heredoc
53
+ # Sequel migration tasks
54
+ namespace :db do
55
+ desc 'Run all migrations in db/migrations'
56
+ task migrate: :connect do
57
+ Sequel.extension(:migration)
58
+ Sequel::Migrator.apply(DB, 'db/migrations')
59
+ end
60
+
61
+ task connect: :environment do
62
+ require './config/initializers/database'
63
+ end
64
+ end
65
+ FILE
66
+ end
67
+
68
+ def gemfile
69
+ <<-FILE.strip_heredoc
70
+ # DB stack
71
+ gem 'sequel'
72
+ gem 'sqlite3'
73
+ FILE
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Starter
4
+ class Config
5
+ CONFIG_FILE = File.join(Dir.getwd, '.config')
6
+ class << self
7
+ def read
8
+ return {} unless File.exist?(CONFIG_FILE)
9
+ YAML.load_file(CONFIG_FILE)
10
+ end
11
+
12
+ def save(dest: Dir.getwd, content: nil)
13
+ return if content.nil? || content.empty?
14
+ File.open(File.join(dest, '.config'), 'w') { |f| f.write(YAML.dump(content)) }
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Starter
4
- VERSION = '0.6.2'
4
+ VERSION = '0.7.0'
5
5
  end
@@ -12,6 +12,9 @@
12
12
  Metrics/LineLength:
13
13
  Max: 120
14
14
 
15
+ Metrics/AbcSize:
16
+ Max: 20
17
+
15
18
  # Offense count: 1
16
19
  # Configuration parameters: CountComments.
17
20
  Metrics/MethodLength:
@@ -14,7 +14,7 @@ gem 'grape-swagger', git: 'git@github.com:ruby-grape/grape-swagger.git'
14
14
  gem 'grape-swagger-entity', git: 'git@github.com:ruby-grape/grape-swagger-entity.git'
15
15
 
16
16
  group :development, :test do
17
- gem 'grape-starter'
17
+ gem 'grape-starter', git: 'git@github.com:LeFnord/grape-starter.git'
18
18
  gem 'pry'
19
19
  gem 'rack-test'
20
20
  gem 'rake'
@@ -26,7 +26,7 @@ $ ./script/test
26
26
  ```
27
27
  $ ./script/server *port (default: 9292)
28
28
  ```
29
- and go to: [http://localhost:port/](http://localhost:9292/)
29
+ and go to: [http://localhost:port/doc](http://localhost:9292/doc)
30
30
  to access the OAPI documentation.
31
31
 
32
32
  For production, set `RACK_ENV=production`
@@ -46,10 +46,12 @@ class App
46
46
  end
47
47
 
48
48
  def call(env)
49
- if env['REQUEST_PATH'].start_with?("/#{Api::Base.prefix}")
49
+ if Api::Base.recognize_path(env['REQUEST_PATH'])
50
50
  Api::Base.call(env)
51
- else
51
+ elsif env['REQUEST_PATH'] == '/doc'
52
52
  DocApp.new.call(env)
53
+ else
54
+ [403, { 'Content-Type': 'text/plain' }, ['403 Forbidden']]
53
55
  end
54
56
  end
55
57
  end
@@ -5,6 +5,10 @@ require 'bundler/setup'
5
5
 
6
6
  Bundler.require :default, ENV['RACK_ENV']
7
7
 
8
+ Dir[File.expand_path('../../config/initializers/*.rb', __FILE__)].each do |initializer|
9
+ require initializer
10
+ end
11
+
8
12
  Dir[File.expand_path('../../lib/**/*.rb', __FILE__)].each do |lib|
9
13
  require lib
10
14
  end
File without changes
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.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - LeFnord
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-12 00:00:00.000000000 Z
11
+ date: 2017-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: '5.1'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '5.0'
40
+ version: '5.1'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rubocop
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.48'
47
+ version: '0.49'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.48'
54
+ version: '0.49'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: awesome_print
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -92,8 +92,11 @@ files:
92
92
  - lib/starter/builder/base_file.rb
93
93
  - lib/starter/builder/file_foo.rb
94
94
  - lib/starter/builder/names.rb
95
- - lib/starter/builder/template_endpoints.rb
96
- - lib/starter/builder/template_files.rb
95
+ - lib/starter/builder/orms.rb
96
+ - lib/starter/builder/templates/endpoints.rb
97
+ - lib/starter/builder/templates/files.rb
98
+ - lib/starter/builder/templates/sequel.rb
99
+ - lib/starter/config.rb
97
100
  - lib/starter/rake/grape_tasks.rb
98
101
  - lib/starter/rspec/request_specs.rb
99
102
  - lib/starter/version.rb
@@ -111,6 +114,7 @@ files:
111
114
  - template/config/application.rb
112
115
  - template/config/boot.rb
113
116
  - template/config/environment.rb
117
+ - template/config/initializers/.keep
114
118
  - template/lib/models.rb
115
119
  - template/lib/models/version.rb
116
120
  - template/public/README
@@ -144,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
148
  version: '0'
145
149
  requirements: []
146
150
  rubyforge_project:
147
- rubygems_version: 2.6.12
151
+ rubygems_version: 2.6.11
148
152
  signing_key:
149
153
  specification_version: 4
150
154
  summary: Create a Grape Rack skeleton