Skip to content

Commit e684d2e

Browse files
committed
Fix ameba errors
1 parent c60a8dc commit e684d2e

File tree

8 files changed

+18
-14
lines changed

8 files changed

+18
-14
lines changed

examples/file-upload/app.cr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ require "kemal"
44
post "/upload" do |env|
55
# Get the uploaded file from the "image" field in the form
66
# The file is initially stored in a temporary location
7-
file = env.params.files["image"].tempfile
7+
uploaded_file = env.params.files["image"].tempfile
88

99
# Construct the destination path where we'll save the file
1010
# - Kemal.config.public_folder is the configured public directory
1111
# - "uploads/" is the subdirectory where we'll store uploads
1212
# - File.basename gets just the filename from the temp file path
13-
file_path = ::File.join [Kemal.config.public_folder, "uploads/", File.basename(file.path)]
13+
uploaded_file_path = ::File.join [Kemal.config.public_folder, "uploads/", File.basename(uploaded_file.path)]
1414

1515
# Open the destination file for writing and copy the uploaded file to it
16-
File.open(file_path, "w") do |f|
17-
IO.copy(file, f)
16+
File.open(uploaded_file_path, "w") do |file|
17+
IO.copy(uploaded_file, file)
1818
end
1919

2020
# Return a simple success message

examples/http-basic-auth/app.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require "kemal-basic-auth"
88
basic_auth "username", "password"
99

1010
# Define a route for the root path "/"
11-
get "/" do |env|
11+
get "/" do |_|
1212
# This route will only execute if authentication is successful
1313
# Otherwise, the browser will show a login prompt
1414
"This is shown if basic auth successful."

examples/json-api/app.cr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ end
1010
USERS = [] of Hash(String, JSON::Any)
1111

1212
# GET - List all users
13-
get "/users" do |env|
13+
get "/users" do |_|
1414
USERS.to_json
1515
end
1616

@@ -29,7 +29,9 @@ end
2929
# POST - Create a new user
3030
post "/users" do |env|
3131
# Parse request body as JSON
32+
# ameba:disable Lint/NotNil
3233
user = JSON.parse(env.request.body.not_nil!.gets_to_end)
34+
# ameba:enable Lint/NotNil
3335
USERS << user.as_h
3436

3537
env.response.status_code = 201
@@ -42,7 +44,9 @@ put "/users/:id" do |env|
4244

4345
if id < USERS.size
4446
# Parse request body as JSON
47+
# ameba:disable Lint/NotNil
4548
updated_user = JSON.parse(env.request.body.not_nil!.gets_to_end)
49+
# ameba:enable Lint/NotNil
4650
USERS[id] = updated_user.as_h
4751
updated_user.to_json
4852
else

examples/json-mapping/app.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ post "/" do |env|
1919
# env.request.body contains the raw JSON data
2020
# not_nil! ensures the body exists
2121
# User.from_json converts the JSON string to a User object
22+
# ameba:disable Lint/NotNil
2223
user = User.from_json env.request.body.not_nil!
24+
# ameba:enable Lint/NotNil
2325

2426
# Convert the user object back to JSON and return it
2527
# This creates a JSON object with username and password fields

examples/mysql-db/app.cr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ class User
2020
end
2121

2222
# List all users
23-
get "/users" do |env|
24-
# Initialize empty array to store User objects
25-
users = [] of User
26-
23+
get "/users" do |_|
2724
# Serialize ResultSet
2825
users = User.from_rs(DBC.query("SELECT * FROM users"))
2926

examples/postgresql-db/app.cr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ class User
2020
end
2121

2222
# List all users
23-
get "/users" do |env|
24-
# Initialize empty array to store User objects
25-
users = [] of User
26-
23+
get "/users" do |_|
2724
# Serialize ResultSet
2825
users = User.from_rs(DBC.query("SELECT * FROM users"))
2926

examples/reuse-port/app.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ end
88
# Start Kemal with custom server configuration
99
Kemal.run do |config|
1010
# Get the server instance from the config
11+
# ameba:disable Lint/NotNil
1112
server = config.server.not_nil!
13+
# ameba:enable Lint/NotNil
1214

1315
# Bind the server to port 3000 with reuse_port enabled
1416
# reuse_port: true allows multiple processes to listen on the same port

examples/unix-domain-socket/app.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ require "kemal"
33
# Start Kemal with custom server configuration to use Unix Domain Socket
44
Kemal.run do |config|
55
# Get the server instance from the config
6+
# ameba:disable Lint/NotNil
67
server = config.server.not_nil!
8+
# ameba:enable Lint/NotNil
79

810
# Bind the server to a Unix Domain Socket instead of TCP port
911
# Unix Domain Sockets provide faster inter-process communication on the same machine

0 commit comments

Comments
 (0)