Skip to content

Commit 080c8cb

Browse files
authored
Rename root route module (#5)
1 parent 59d6a6b commit 080c8cb

File tree

13 files changed

+57
-56
lines changed

13 files changed

+57
-56
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,5 @@ build-iPhoneSimulator/
122122

123123
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
124124
.idea/
125-
config/jwt/*
125+
config/jwt/*.key*
126126
.dccache

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
3333
docker compose up --build
3434
```
3535

36+
- Setup and seed the database.
37+
38+
```
39+
docker compose exec app bundle exec rake db:setup
40+
```
41+
42+
- Visit your API at http://localhost:3000
43+
3644
## Creating a user
3745

3846
- Run the create users Rake task.

Rakefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env rake
22
# frozen_string_literal: true
33

4-
require 'rubygems'
54
require 'bundler'
65

76
ENV['RAKE_ENV'] ||= 'development'
@@ -37,12 +36,12 @@ begin
3736
require 'bundler/audit/task'
3837
Bundler::Audit::Task.new
3938
rescue LoadError
40-
puts 'Not loading RSpec or Rubocop.'
39+
puts 'Not loading development only rake tasks.'
4140
end
4241

4342
# Shows app routes
4443
task routes: :environment do
45-
API::Root.routes.each do |route|
44+
GrapeApiBoilerplate::Api::Root.routes.each do |route|
4645
method = route.request_method.ljust(10)
4746
path = route.origin
4847
puts " #{method} #{path}"

app/api/helpers.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# frozen_string_literal: true
22

3-
module API
4-
module Helpers
5-
def logger
6-
Root.logger
3+
module GrapeApiBoilerplate
4+
module Api
5+
module Helpers
6+
def logger
7+
Root.logger
8+
end
79
end
810
end
911
end

app/root.rb

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
11
# frozen_string_literal: true
22

3-
module API
4-
class Root < Grape::API
5-
format :json
6-
default_format :json
7-
content_type :json, 'application/json'
8-
prefix :api
3+
module GrapeApiBoilerplate
4+
module Api
5+
class Root < Grape::API
6+
format :json
7+
default_format :json
8+
content_type :json, 'application/json'
9+
prefix :api
910

10-
rescue_from :grape_exceptions
11+
rescue_from :grape_exceptions
1112

12-
# Logging
13-
insert_before Grape::Middleware::Error, GrapeLogging::Middleware::RequestLogger,
14-
{
15-
logger:,
16-
formatter: GrapeLogging::Formatters::Json.new,
17-
include: [GrapeLogging::Loggers::FilterParameters.new([:password])]
18-
}
13+
# Logging
14+
insert_before Grape::Middleware::Error, GrapeLogging::Middleware::RequestLogger,
15+
{
16+
logger:,
17+
formatter: GrapeLogging::Formatters::Json.new,
18+
include: [GrapeLogging::Loggers::FilterParameters.new([:password])]
19+
}
1920

20-
# Helpers
21-
helpers do
22-
include Helpers
23-
end
21+
# Helpers
22+
helpers do
23+
include Helpers
24+
end
2425

25-
# Routes
26-
mount GrapeApiBoilerplate::Api::Endpoints::Session
27-
mount GrapeApiBoilerplate::Api::Endpoints::V1::HelloWorldEndpoint
28-
mount GrapeApiBoilerplate::Api::Endpoints::V1::WidgetEndpoint
26+
# Routes
27+
mount GrapeApiBoilerplate::Api::Endpoints::Session
28+
mount GrapeApiBoilerplate::Api::Endpoints::V1::HelloWorldEndpoint
29+
mount GrapeApiBoilerplate::Api::Endpoints::V1::WidgetEndpoint
2930

30-
add_swagger_documentation \
31-
info: {
32-
title: 'Grape Boilerplate',
33-
description: 'A full-featured API boilerplate to get you started with the Grape framework.'
34-
}
31+
add_swagger_documentation \
32+
info: {
33+
title: 'Grape Boilerplate',
34+
description: 'A full-featured API boilerplate to get you started with the Grape framework.'
35+
}
3536

36-
# Handle 404s
37-
route :any, '*path' do
38-
error!({ message: 'resource does not exist' }, 404)
37+
# Handle 404s
38+
route :any, '*path' do
39+
error!({ message: 'resource does not exist' }, 404)
40+
end
3941
end
4042
end
4143
end

config.ru

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ use OTR::ActiveRecord::ConnectionManagement
1414
# Load Swagger UI when running locally.
1515
use Rack::Static, urls: ['/public/swagger'] unless ENV['RACK_ENV'] == 'production'
1616

17-
API::Root.compile!
18-
run API::Root
17+
GrapeApiBoilerplate::Api::Root.compile!
18+
run GrapeApiBoilerplate::Api::Root

config/boot.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# frozen_string_literal: true
22

3-
require 'rubygems'
43
require 'bundler/setup'
54
require 'rack/cors'

config/jwt/.gitkeep

Whitespace-only changes.

docker-compose.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ services:
55
build:
66
context: .
77
dockerfile: dev.Dockerfile
8-
container_name: ruby-grape
98
environment:
109
RACK_ENV: development
1110
WEB_CONCURRENCY: "0"

spec/api/hello_world_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
require 'spec_helper'
44

5-
describe API::Root do
5+
describe GrapeApiBoilerplate::Api::Root do
66
include Rack::Test::Methods
77

88
def app
9-
API::Root
9+
GrapeApiBoilerplate::Api::Root
1010
end
1111

1212
it 'gets hello world' do

0 commit comments

Comments
 (0)