grape-starter 0.3.1 → 0.4.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: 2ca5b09c3e3577d7a93143d6fff88b91aecfd926
4
- data.tar.gz: 8cd9948d9aa98b6c12cd118cca08d3d1858ad62f
3
+ metadata.gz: '0823711b471e505ebfbd048f139fa0276f4ebf41'
4
+ data.tar.gz: e784796595cc5ac6d3c43ad1a6c0317b35c0467a
5
5
  SHA512:
6
- metadata.gz: 22665163096ced52badfbdd0b99e2373108f18c0a6ae68002bad33d525b75b408d807fd9cca10c91dd49631fbef466d85c69bd9a72f39fddabd32b022ad00490
7
- data.tar.gz: 83e99286b0d75e30ea70b80f7430918179178982c5dd4ea1958ce9632cd20c13ee6262f908ab742cea05b9d3778344c6723e84d69560164bf9761f2f8ce7c9d8
6
+ metadata.gz: 67113631c915da4adead1ee145c1640ebaa1e8131dbeef240c5ed354f3be8919223f743a241ba73cb5085fbe35e40499765008b0280c5f0f5d809f3f36bc12ef
7
+ data.tar.gz: 4b6ba9fcd7b2b0de31a6022a72d57cf5eea654ebb2fd9b11a852a4fd3fb9b0902e6328da229cfd4b11478debf1400df8ffc7926fc55f450a62a6f1ce23d5070e
data/.inch.yml CHANGED
@@ -2,4 +2,5 @@ files:
2
2
  excluded:
3
3
  - lib/starter/builder/template_endpoints.rb
4
4
  - lib/starter/builder/template_files.rb
5
+ - lib/starter/builder/names.rb
5
6
  - lib/starter/rake/grape_tasks.rb
@@ -9,4 +9,4 @@
9
9
  # Offense count: 1
10
10
  # Configuration parameters: CountComments.
11
11
  Metrics/MethodLength:
12
- Max: 13
12
+ Max: 20
@@ -6,7 +6,7 @@ before_install:
6
6
 
7
7
  matrix:
8
8
  include:
9
- - rvm: 2.4.0-rc1
9
+ - rvm: 2.4.0
10
10
  - rvm: 2.3.3
11
11
  - rvm: 2.2.6
12
12
  - rvm: ruby-head
data/Rakefile CHANGED
@@ -11,4 +11,4 @@ RSpec::Core::RakeTask.new(:spec)
11
11
  require 'rubocop/rake_task'
12
12
  RuboCop::RakeTask.new(:rubocop)
13
13
 
14
- task default: [:spec]
14
+ task default: [:spec, :rubocop]
@@ -19,11 +19,9 @@ arguments :strict
19
19
  desc 'overwrites existend stuff'
20
20
  switch [:f, :force], negatable: false
21
21
 
22
- desc 'Create initial grape api skeleton'
23
- arg_name 'project name'
24
-
22
+ desc 'Creates initial api skeleton'
23
+ arg_name 'awesome_api'
25
24
  command :new do |c|
26
-
27
25
  c.action do |global_options, _, args|
28
26
  dest = args.empty? ? nil : File.join(Dir.getwd, args.first)
29
27
 
@@ -49,12 +47,9 @@ command :new do |c|
49
47
  end
50
48
  end
51
49
 
52
- desc 'Adds a new resource - run from inside the project'
53
- long_desc "
54
- params: \n
55
- resource - to add, it respects the numerus of it (required)\n
56
- http_verbs - specify which end-points should be created, if nothings given CRUD would be writen
57
- "
50
+ desc 'Adds given new resource'
51
+ long_desc "Adds given resource, hereby the numerus of the provided
52
+ resource would be respected to create singular or plural endpoints"
58
53
  arg_name 'resource [post* get* put* patch* delete*]'
59
54
  command :add do |c|
60
55
  c.desc 'adds entity file'
@@ -79,7 +74,7 @@ command :add do |c|
79
74
  end
80
75
  end
81
76
 
82
- desc 'Removes a resource - run from inside the project'
77
+ desc 'Removes given resource'
83
78
  arg_name 'resource'
84
79
  command :rm do |c|
85
80
  c.desc 'removes also entity file'
@@ -22,9 +22,11 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_dependency 'gli', '~> 2.14'
26
- spec.add_dependency 'activesupport', '~> 5.0'
27
- spec.add_dependency 'rubocop', '~> 0.40'
25
+ spec.required_ruby_version = '>= 2.2.6'
26
+
27
+ spec.add_dependency 'gli', '>= 2.14'
28
+ spec.add_dependency 'activesupport', '>= 5.0.0'
29
+ spec.add_dependency 'rubocop', '>= 0.40.0'
28
30
 
29
31
  spec.add_development_dependency 'rake', '~> 10.0'
30
32
  spec.add_development_dependency 'grape', '~> 0.18'
@@ -14,11 +14,7 @@ module Starter
14
14
  class << self
15
15
  attr_reader :resource, :set, :force, :entity, :destination
16
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
17
+ # would be called from new command
22
18
  #
23
19
  # name - A String as project name
24
20
  # source - A String which provides the template path
@@ -29,10 +25,10 @@ module Starter
29
25
 
30
26
  FileUtils.copy_entry source, destination
31
27
 
32
- replace_static(File.join('script','server'))
28
+ replace_static(File.join('script', 'server'))
33
29
  end
34
30
 
35
- # would be called on add command
31
+ # would be called from add command
36
32
  #
37
33
  # resource - A String as name
38
34
  # options - A Hash to provide some optional arguments (default: {})
@@ -49,7 +45,8 @@ module Starter
49
45
  self
50
46
  end
51
47
 
52
- # it saves the files
48
+ #
49
+ # … it saves the files
53
50
  def save
54
51
  created_files = file_list.each_with_object([]) do |new_file, memo|
55
52
  memo << send("#{new_file}_name")
@@ -61,7 +58,7 @@ module Starter
61
58
  created_files
62
59
  end
63
60
 
64
- # would be called on rm command
61
+ # would be called on from command
65
62
  #
66
63
  # resource - A String, which indicates the resource to remove
67
64
  # options - A Hash to provide some optional arguments (default: {})
@@ -86,14 +83,21 @@ module Starter
86
83
  content(endpoint_set).join("\n\n")
87
84
  end
88
85
 
89
- # privdes the specs for the endpoints of the resource
86
+ # provides the specs for the endpoints of the resource
90
87
  def endpoint_specs
91
88
  content(endpoint_set.map { |x| "#{x}_spec" }).join("\n")
92
89
  end
93
90
 
94
91
  private
95
92
 
96
- # provides an array of endpoints to for the new resource
93
+ # get content for and save new resource files
94
+ def save_file(new_file)
95
+ new_file_name = "#{new_file}_name"
96
+ should_raise?(send(new_file_name))
97
+ write_file(send(new_file_name), send(new_file.strip_heredoc))
98
+ end
99
+
100
+ # provides an array of endpoints for the new resource
97
101
  def endpoint_set
98
102
  crud_set = singular? ? singular_one : crud
99
103
  return crud_set if set.blank?
@@ -108,39 +112,29 @@ module Starter
108
112
  entity ? standards + ['entity_file'] : standards
109
113
  end
110
114
 
111
- # raises if resource exist and force == false
115
+ # raises if resource exist and force false
112
116
  def should_raise?(file)
113
117
  raise StandardError, '… resource exists' if File.exist?(file) && !force
114
118
  end
115
119
 
116
- # add project name to static files
120
+ # replace something in exitend files
121
+ #
122
+ # will be called on project creation
123
+ #
124
+ # … static files such as under script folder,
117
125
  def replace_static(file)
118
126
  server_file = File.join(destination, file)
119
127
 
120
128
  file_foo(server_file) { |content| content.gsub!('{{{grape-starter}}}', "API-#{resource}") }
121
129
  end
122
130
 
131
+ # will be called an resource creation
132
+ #
133
+ # … add it in api base
123
134
  def add_mount_point
124
135
  file_foo(api_base_file_name) { |content| add_to_base(content) }
125
136
  end
126
137
 
127
- def remove_mount_point
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)
135
- end
136
-
137
- def save_file(new_file)
138
- new_file_name = "#{new_file}_name"
139
- should_raise?(send(new_file_name))
140
- write_file(send(new_file_name), send(new_file.strip_heredoc))
141
- end
142
-
143
- # manipulating API Base file
144
138
  # … adding
145
139
  def add_to_base(file)
146
140
  occurence = file.scan(/(\s+mount\s.*?\n)/).last.first
@@ -148,18 +142,30 @@ module Starter
148
142
  file.sub!(occurence, replacement)
149
143
  end
150
144
 
145
+ # … remove it in api base
146
+ def remove_mount_point
147
+ file_foo(api_base_file_name) { |content| remove_from_base(content) }
148
+ end
149
+
151
150
  # … removing
152
151
  def remove_from_base(file)
153
152
  file.sub!(mount_point, '')
154
153
  end
155
154
 
156
155
  # content of the given set of files,
157
- # returns an array of string
158
156
  def content(set)
159
157
  set.map { |x| send(x) }
160
158
  end
161
159
 
162
- # general file
160
+ # general file stuff
161
+ #
162
+ # … reading and writing content
163
+ def file_foo(file)
164
+ content = read_file(file)
165
+ yield content
166
+ write_file(file, content)
167
+ end
168
+
163
169
  # … read
164
170
  def read_file(file)
165
171
  File.read(file)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Starter
3
- VERSION = '0.3.1'
3
+ VERSION = '0.4.0'
4
4
  end
@@ -15,7 +15,7 @@ Metrics/LineLength:
15
15
  # Offense count: 1
16
16
  # Configuration parameters: CountComments.
17
17
  Metrics/MethodLength:
18
- Max: 10
18
+ Max: 20
19
19
 
20
20
  Style/AsciiComments:
21
21
  Enabled: false
@@ -9,9 +9,9 @@ gem 'rack-cors'
9
9
  # TODO: revert to gem after mörge and release
10
10
  gem 'grape', git: 'git@github.com:ruby-grape/grape.git'
11
11
  # gem 'grape', '~> 0.18'
12
- gem 'grape-entity', '~> 0.6'
13
- gem 'grape-swagger', '~> 0.25'
14
- gem 'grape-swagger-entity', '~> 0.1.5'
12
+ gem 'grape-entity', '>= 0.6.0'
13
+ gem 'grape-swagger', '>= 0.25.0'
14
+ gem 'grape-swagger-entity', '>= 0.1.5'
15
15
 
16
16
  group :development, :test do
17
17
  gem 'grape-starter'
@@ -1,6 +1,8 @@
1
- # frozen_string_literal: true
2
-
1
+ # frozen_string_literal: false
3
2
  require 'rack/cors'
3
+
4
+ use Rack::CommonLogger
5
+
4
6
  use Rack::Cors do
5
7
  allow do
6
8
  origins '*'
@@ -8,9 +10,10 @@ use Rack::Cors do
8
10
  end
9
11
  end
10
12
 
11
- require 'rack/static'
12
- use Rack::Static, urls: '/', root: 'public', index: 'redoc.html'
13
-
14
13
  require File.expand_path('../config/application', __FILE__)
15
14
 
16
- run Api::Base
15
+ app = App.new
16
+ app.map '/', DocApp.new
17
+ app.map '/api', Api::Base
18
+
19
+ run app
@@ -20,3 +20,59 @@ Dir[File.expand_path('../../api/endpoints/*.rb', __FILE__)].each do |endpoint|
20
20
  end
21
21
 
22
22
  require 'base'
23
+
24
+ require 'rack'
25
+
26
+ # provides the documentation of the API
27
+ class DocApp
28
+ def call(env)
29
+ [200, { 'Content-Type' => 'text/html' }, [re_doc(env)]]
30
+ end
31
+
32
+ def re_doc(env)
33
+ doc = template.sub('{{{server}}}', env['SERVER_NAME'])
34
+ doc = doc.sub('{{{port}}}', env['SERVER_PORT'])
35
+
36
+ doc
37
+ end
38
+
39
+ def template
40
+ "<!DOCTYPE html>
41
+ <html>
42
+ <head>
43
+ <title>ReDoc API documentation</title>
44
+ <meta name='viewport' content='width=device-width, initial-scale=1'>
45
+ <style>
46
+ body {
47
+ margin: 0;
48
+ padding: 0;
49
+ }
50
+ </style>
51
+ </head>
52
+ <body>
53
+ <redoc spec-url='http://{{{server}}}:{{{port}}}/api/v1/oapi.json'></redoc>
54
+ <script src='https://rebilly.github.io/ReDoc/releases/latest/redoc.min.js'> </script>
55
+ </body>
56
+ </html>"
57
+ end
58
+ end
59
+
60
+ # provides the routing between the API and the html documentation of it
61
+ class App
62
+ def initialize
63
+ @apps = {}
64
+ end
65
+
66
+ def map(route, app)
67
+ @apps[route] = app
68
+ end
69
+
70
+ def call(env)
71
+ request = Rack::Request.new(env)
72
+ if env['REQUEST_PATH'].start_with?('/api')
73
+ @apps['/api'].call(env)
74
+ elsif @apps[request.path]
75
+ @apps[request.path].call(env)
76
+ end
77
+ end
78
+ end
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env bash
1
+ #!/usr/bin/env bash -l
2
2
 
3
3
  set -e
4
4
 
@@ -8,13 +8,15 @@ test -z "$RACK_ENV" &&
8
8
  RACK_ENV='development'
9
9
 
10
10
  if [ $1 ]; then
11
- port=$1
11
+ PORT=$1
12
12
  else
13
- port=9292
13
+ PORT=9292
14
14
  fi
15
15
 
16
+ export PORT=$PORT
17
+
16
18
  if [ "$RACK_ENV" = 'production' ]; then
17
- bundle exec thin start -p $port -e $RACK_ENV --tag {{{grape-starter}}} -d --threaded
19
+ bundle exec thin start -p $PORT -e $RACK_ENV --tag {{{grape-starter}}} -d --threaded
18
20
  else
19
- bundle exec thin start -p $port -e $RACK_ENV --tag {{{grape-starter}}} -V -D
21
+ bundle exec thin start -p $PORT -e $RACK_ENV --tag {{{grape-starter}}} -D
20
22
  fi
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
 
4
4
  RSpec.describe Api::Base do
5
5
  subject(:swagger) do
6
- get '/api/v1/swagger_doc'
6
+ get '/api/v1/oapi'
7
7
  last_response
8
8
  end
9
9
 
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-starter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
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-21 00:00:00.000000000 Z
11
+ date: 2016-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.14'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.14'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: 5.0.0
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.0.0
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.40'
47
+ version: 0.40.0
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.40'
54
+ version: 0.40.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -205,7 +205,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
205
  requirements:
206
206
  - - ">="
207
207
  - !ruby/object:Gem::Version
208
- version: '0'
208
+ version: 2.2.6
209
209
  required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  requirements:
211
211
  - - ">="