Skip to content

Commit

Permalink
Rubocop fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Arie committed Jan 11, 2021
1 parent e3f0156 commit b207a06
Show file tree
Hide file tree
Showing 56 changed files with 427 additions and 406 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/rails.yml
Expand Up @@ -28,6 +28,18 @@ jobs:
run: |
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
rubocop:
name: Rubocop
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup Ruby
uses: ruby/setup-ruby@v1
- name: Install Rubocop
run: gem install rubocop
- name: Check code
run: rubocop
rspec:
name: RSpec
runs-on: ubuntu-latest
Expand Down
8 changes: 8 additions & 0 deletions .rubocop.yml
Expand Up @@ -16,6 +16,14 @@ Metrics/ClassLength:
Metrics/AbcSize:
Enabled: false

Metrics/PerceivedComplexity:
Enabled: false
Max: 10

Metrics/CyclomaticComplexity:
Enabled: false
Max: 12

Style/GlobalVars:
Enabled: false

Expand Down
12 changes: 6 additions & 6 deletions app/behaviour/ftp_access.rb
Expand Up @@ -5,14 +5,14 @@ module FtpAccess

def demos
@demos ||= begin
list_files('/', '*.dem').map { |file| "#{tf_dir}/#{file}" }
end
list_files('/', '*.dem').map { |file| "#{tf_dir}/#{file}" }
end
end

def logs
@logs ||= begin
list_files('logs', '*.log').map { |file| "#{tf_dir}/logs/#{file}" }
end
@logs ||= begin
list_files('logs', '*.log').map { |file| "#{tf_dir}/logs/#{file}" }
end
end

def list_files(dir, pattern = '*')
Expand Down Expand Up @@ -44,7 +44,7 @@ def copy_from_server(files, destination)
ftp = make_ftp_connection
files_for_thread.each do |file|
ftp.getbinaryfile(file, File.join(destination, File.basename(file)))
rescue Exception => e
rescue StandardError => e
Rails.logger.error "couldn't download file: #{file} - #{e}"
Raven.capture_exception(e) if Rails.env.production?
end
Expand Down
4 changes: 2 additions & 2 deletions app/behaviour/reservation_server_information.rb
Expand Up @@ -37,7 +37,7 @@ def zipfile_url
"#{SITE_URL}/uploads/#{zipfile_name}"
end

def has_players?
last_number_of_players.to_i > 0
def players_playing?
last_number_of_players.to_i.positive?
end
end
2 changes: 1 addition & 1 deletion app/behaviour/reservation_validations.rb
Expand Up @@ -14,7 +14,7 @@ def self.included(mod)
validates_with Reservations::OnlyOneFutureReservationPerUserValidator, unless: :donator?
validates_with Reservations::StartsNotTooFarInFutureValidator, unless: :donator?
validates_with Reservations::MapIsValidValidator
validates_with Reservations::GameyeLocationSelectedValidator, if: :gameye?
validates_with Reservations::GameyeLocationSelectedValidator, if: :gameye?
validates_with Reservations::CustomWhitelistValidator

def check_server_available?
Expand Down
80 changes: 41 additions & 39 deletions app/controllers/api/application_controller.rb
@@ -1,56 +1,58 @@
# frozen_string_literal: true

class Api::ApplicationController < ActionController::Base
respond_to :json
rescue_from ActiveRecord::RecordNotFound, with: :handle_not_found
rescue_from ActionController::ParameterMissing, with: :handle_unprocessable_entity
module Api
class ApplicationController < ActionController::Base
respond_to :json
rescue_from ActiveRecord::RecordNotFound, with: :handle_not_found
rescue_from ActionController::ParameterMissing, with: :handle_unprocessable_entity

before_action :verify_api_key
before_action :set_default_response_format
before_action :verify_api_key
before_action :set_default_response_format

def verify_api_key
api_user
end
def verify_api_key
api_user
end

def api_user
@api_user ||= authenticate_params || authenticate_token || unauthorized
end
def api_user
@api_user ||= authenticate_params || authenticate_token || unauthorized
end

def uid_user
@uid_user ||= User.find_by_uid(params[:steam_uid])
end
def uid_user
@uid_user ||= User.find_by_uid(params[:steam_uid])
end

def current_user
@current_user ||= (api_user&.admin? && uid_user) || api_user
end
def current_user
@current_user ||= (api_user&.admin? && uid_user) || api_user
end

def handle_not_found
head :not_found
end
def handle_not_found
head :not_found
end

def handle_unprocessable_entity
Rails.logger.warn "UNPROCESSABLE ENTITY: #{request.body.read}"
head :unprocessable_entity
end
def handle_unprocessable_entity
Rails.logger.warn "UNPROCESSABLE ENTITY: #{request.body.read}"
head :unprocessable_entity
end

private
private

def authenticate_params
User.find_by(api_key: params[:api_key]) if params[:api_key]
end
def authenticate_params
User.find_by(api_key: params[:api_key]) if params[:api_key]
end

def authenticate_token
authenticate_with_http_token do |token, _options|
User.find_by(api_key: token)
def authenticate_token
authenticate_with_http_token do |token, _options|
User.find_by(api_key: token)
end
end
end

def unauthorized
head :unauthorized
nil
end
def unauthorized
head :unauthorized
nil
end

def set_default_response_format
request.format = :json
def set_default_response_format
request.format = :json
end
end
end
78 changes: 40 additions & 38 deletions app/controllers/api/donators_controller.rb
@@ -1,51 +1,53 @@
# frozen_string_literal: true

class Api::DonatorsController < Api::ApplicationController
before_action :require_admin

def show
@user = Group.donator_group.users.find_by(uid: params[:id])
if @user && (@donator = @user.group_users.find_by(group_id: Group.donator_group.id))
render :show
else
head :not_found
module Api
class DonatorsController < Api::ApplicationController
before_action :require_admin

def show
@user = Group.donator_group.users.find_by(uid: params[:id])
if @user && (@donator = @user.group_users.find_by(group_id: Group.donator_group.id))
render :show
else
head :not_found
end
end
end

def new
@user = GroupUser.new
render :new
end
def new
@user = GroupUser.new
render :new
end

def create
@user = User.find_by_uid(donator_params[:steam_uid])
if @user
@donator = Group.donator_group.group_users.find_or_initialize_by(user_id: @user.id)
@donator.expires_at = donator_params[:expires_at]
@donator.save
render :show
else
head :not_found
def create
@user = User.find_by_uid(donator_params[:steam_uid])
if @user
@donator = Group.donator_group.group_users.find_or_initialize_by(user_id: @user.id)
@donator.expires_at = donator_params[:expires_at]
@donator.save
render :show
else
head :not_found
end
end
end

def destroy
group_users = Group.donator_group.group_users.joins(:user).where(users: { uid: params[:id] })
if group_users.any?
group_users.update_all(expires_at: 1.second.ago)
head :no_content
else
head :not_found
def destroy
group_users = Group.donator_group.group_users.joins(:user).where(users: { uid: params[:id] })
if group_users.any?
group_users.update_all(expires_at: 1.second.ago)
head :no_content
else
head :not_found
end
end
end

def donator_params
params.require(:donator).permit(:steam_uid, :expires_at)
end
def donator_params
params.require(:donator).permit(:steam_uid, :expires_at)
end

private
private

def require_admin
api_user&.admin? || unauthorized
def require_admin
api_user&.admin? || unauthorized
end
end
end
10 changes: 6 additions & 4 deletions app/controllers/api/maps_controller.rb
@@ -1,8 +1,10 @@
# frozen_string_literal: true

class Api::MapsController < Api::ApplicationController
def index
@maps = MapUpload.available_maps
@cloud_maps = MapUpload.available_cloud_maps
module Api
class MapsController < Api::ApplicationController
def index
@maps = MapUpload.available_maps
@cloud_maps = MapUpload.available_cloud_maps
end
end
end

0 comments on commit b207a06

Please sign in to comment.