From 9fab7393f71a56190639cbf6bc3cedf3364a58b7 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Sun, 7 Jul 2024 16:26:38 -0500 Subject: [PATCH] Fix lint errors --- Gemfile | 4 ++-- app.rb | 23 +++++++++++------------ app_test.rb | 10 +++++----- config.ru | 8 ++++---- config/puma.rb | 2 +- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/Gemfile b/Gemfile index ba47789..acfb954 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source "https://rubygems.org" gem "sinatra" -gem 'sinatra-contrib' +gem "sinatra-contrib" gem "puma" gem "rackup" @@ -11,7 +11,7 @@ gem "nanoid" gem "ulid" gem "uuid7" -gem 'jwt' +gem "jwt" group :development do gem "ruby-lsp" diff --git a/app.rb b/app.rb index 408260f..b9bce59 100644 --- a/app.rb +++ b/app.rb @@ -15,7 +15,7 @@ require "jwt" SESSION_SECRET_HEX_LENGTH = 64 -set :session_secret, ENV.fetch('SESSION_SECRET') { SecureRandom.hex(SESSION_SECRET_HEX_LENGTH) } +set :session_secret, ENV.fetch("SESSION_SECRET") { SecureRandom.hex(SESSION_SECRET_HEX_LENGTH) } CLK_TCK = 100 PID_FILE_PATH = "/run/app/pid".freeze @@ -35,7 +35,7 @@ DURATION_PARTS = [ [SECONDS_PER_DAY, "day", "d"], [SECONDS_PER_HOUR, "hour", "h"], [SECONDS_PER_MINUTE, "minute", "m"], - [1, "second", "s"], + [1, "second", "s"] ].freeze JWT_SECRET = SecureRandom.bytes(64).freeze @@ -44,8 +44,8 @@ module Sinatra module RequestHeadersHelper def req_headers hash = request.env.select { |k, _| k.start_with? "HTTP_" } - .collect { |k, v| [k.gsub(/^HTTP_/, "").gsub(/_/, "-").downcase, v] } - .sort + .collect { |k, v| [k.gsub(/^HTTP_/, "").tr("_", "-").downcase, v] } + .sort h = Rack::Headers.new h.merge hash end @@ -90,7 +90,7 @@ module UpDown def to_json(*_args) return unless enabled? - JSON.generate({ "status" => "ok" }) + JSON.generate({"status" => "ok"}) end end @@ -203,7 +203,7 @@ end before do # content_type 'text/plain' - sleep(1) while Sleep.instance.asleep? unless request.path_info == "/livez/sleep" + sleep(1) while Sleep.instance.asleep? && request.path_info != "/livez/sleep" end get "/" do @@ -249,7 +249,7 @@ end get "/livez/uptime" do tt = TickTock.new - x = { started_at: tt.started_at, seconds: tt.uptime.to_i, human: human_time(tt.uptime.to_i) } + x = {started_at: tt.started_at, seconds: tt.uptime.to_i, human: human_time(tt.uptime.to_i)} json x end @@ -304,16 +304,15 @@ post "/halt" do end get "/pid" do - JSON.generate({ puma: master_pid, pid: Process.pid }) + JSON.generate({puma: master_pid, pid: Process.pid}) end get "/token" do exp = Time.now.to_i + SECONDS_PER_MINUTE * 2 - payload = { name: "anonymous", exp: exp, jti: Random.uuid } + payload = {name: "anonymous", exp: exp, jti: Random.uuid} expires_at = Time.at(exp).to_datetime token = JWT.encode payload, JWT_SECRET, "HS256" - token - x = { :token => token, :expires_at => expires_at } + x = {token: token, expires_at: expires_at} json x end @@ -330,7 +329,7 @@ end get "/session" do j = session.to_hash - j[:hostname] = ENV['HOSTNAME'] + j[:hostname] = ENV["HOSTNAME"] json j end diff --git a/app_test.rb b/app_test.rb index 653da06..1d355db 100644 --- a/app_test.rb +++ b/app_test.rb @@ -1,8 +1,8 @@ -ENV['APP_ENV'] = 'test' +ENV["APP_ENV"] = "test" -require './app' -require 'test/unit' -require 'rack/test' +require "./app" +require "test/unit" +require "rack/test" class ToyTest < Test::Unit::TestCase include Rack::Test::Methods @@ -12,7 +12,7 @@ class ToyTest < Test::Unit::TestCase end def test_root - get '/' + get "/" assert last_response.ok? assert_equal "hello there!\n", last_response.body end diff --git a/config.ru b/config.ru index cbc11d2..546d4cb 100644 --- a/config.ru +++ b/config.ru @@ -1,6 +1,6 @@ -require 'bundler/setup' -require 'sinatra' +require "bundler/setup" +require "sinatra" -require './app' +require "./app" -run Sinatra::Application \ No newline at end of file +run Sinatra::Application diff --git a/config/puma.rb b/config/puma.rb index 7076950..2d4827a 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,3 +1,3 @@ # workers 3 -pidfile '/run/app/pid' +pidfile "/run/app/pid" preload_app!