Skip to content

Commit 6378def

Browse files
committed
Fixes rubocop errors
1 parent a96092a commit 6378def

39 files changed

+65
-246
lines changed

app/controllers/admin/mail_aliases_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def update
2020
@aliases = MailAlias.insert_aliases! mail_alias_params[:username],
2121
mail_alias_params[:domain],
2222
mail_alias_params[:targets] || []
23-
rescue ActiveRecord::RecordInvalid => ex
23+
rescue ActiveRecord::RecordInvalid
2424
render nothing: true, status: :unprocessable_entity
2525
return
2626
end

app/controllers/adventures_controller.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ def set_mission_variables(adventure)
3535
@group = current_user.groups.regular.last
3636

3737
@adventure_missions.each do |am|
38-
@group_points_sum += am.points(@group)
38+
@group_points_sum += am.points_per_group(@group)
3939
end
4040

4141
@adventure_missions.map do |am|
4242
am.finished = am.finished?(@group)
43-
am.points = am.points(@group)
43+
am.points = am.points_per_group(@group)
4444
end
4545

4646
@grid = initialize_grid(@adventure_missions, locale: :sv, order: "adventure_missions.index")

app/controllers/api/push_devices_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def create
1414
def destroy
1515
@push_device = current_user.push_devices.find_by(token: params[:token])
1616

17-
if @push_device && @push_device.destroy
17+
if @push_device&.destroy
1818
render json: {}, status: :ok
1919
else
2020
render json: {errors: "Failed to destroy push device"}, status: 422

app/controllers/cafe_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def competition
2323
def ladybug
2424
authorize_admin!(:ladybug, :cafe)
2525

26-
@date = if date = ladybug_date
26+
@date = if (date = ladybug_date)
2727
Time.zone.parse(date)
2828
else
2929
Time.zone.now

app/helpers/notification_helper.rb

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ def notification_context(notification, data)
44
end
55

66
def notification_icon(notification)
7-
icon = ""
87
if notification.notifyable_type == "EventUser"
98
if notification.mode == "position"
109
icon("fas", "check")

app/models/adventures/adventure_mission.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def accepted?(group)
2727
finished?(group) && adventure_mission_groups.by_group(group).first.pending == false
2828
end
2929

30-
def points(group)
30+
def points_per_group(group)
3131
# Points only rewarded once mission is accepted
3232
if accepted?(group)
3333
adventure_mission_groups.by_group(group).first.points.to_i

app/models/cars/rent.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def p_time
6262

6363
# Requests route-helper to print url and path
6464
def p_url
65-
Rails.application.routes.url_helpers.rent_url(id, host: PUBLIC_URL)
65+
Rails.application.routes.url_helpers.rent_url(id, host: Rails.application.config.public_url)
6666
end
6767

6868
def p_path

app/models/constant.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ class Constant < ApplicationRecord
55

66
def self.get(name)
77
c = Constant.where(name: name).first
8-
c && c.value || ""
8+
c&.value.presence || ""
99
end
1010
end

app/models/council.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def to_param
4141
end
4242

4343
def p_url
44-
Rails.application.routes.url_helpers.council_url(id, host: PUBLIC_URL)
44+
Rails.application.routes.url_helpers.council_url(id, host: Rails.application.config.public_url)
4545
end
4646

4747
def p_path

app/models/introduction.rb

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ class Introduction < ApplicationRecord
55
globalize_accessors(locales: [:en, :sv],
66
attributes: [:title, :description])
77

8-
attr_reader :dates, :events_by_day, :dates_by_week
9-
108
has_many :groups, dependent: :destroy
119
has_many :group_users, through: :groups
1210
has_many :users, through: :groups

app/models/messages/message_token.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def self.add(user_id)
1515
expires = 30.seconds.from_now.to_i
1616
redis.expireat(KEY_BASE + token, expires)
1717

18-
data = {token: token, expires: expires}
18+
{token: token, expires: expires}
1919
end
2020

2121
# Finds the user_id for a token and removes the token

app/models/nomination.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Nomination < ApplicationRecord
99

1010
def candidate_url
1111
Rails.application.routes.url_helpers.new_candidate_url(post: post,
12-
host: PUBLIC_URL)
12+
host: Rails.application.config.public_url)
1313
end
1414

1515
private

app/models/notifications/notification.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ def valid_notifyable
4141
end
4242

4343
def allowed_class?(notifyable)
44-
ALLOWED.keys.include?(notifyable.class.name)
44+
ALLOWED.key?(notifyable.class.name)
4545
end
4646

4747
def allowed_mode?(notifyable, mode)
48-
ALLOWED[notifyable.class.name].keys.include?(mode)
48+
ALLOWED[notifyable.class.name].key?(mode)
4949
end
5050

5151
def update_counter_cache

app/models/user.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def program_year
8888
str = "F" if program == PHYSICS
8989
str = "Pi" if program == MATH
9090
str = "N" if program == NANO
91-
str += start_year.to_s.split("").last(2).join if start_year.present?
91+
str += start_year.to_s.chars.last(2).join if start_year.present?
9292
str
9393
end
9494

app/serializers/api/cafe_shift_serializer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def isme
1717
def councils
1818
councils = object.cafe_worker&.councils
1919

20-
council_map = {
20+
{
2121
chosen: councils&.map { |c| [c.title, c.id] }.to_h,
2222
available: @instance_options[:current_user].councils.map { |c| [c.title, c.id] }.to_h
2323
}

app/serializers/api/news_serializer.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def content
99
end
1010

1111
def image
12-
PUBLIC_URL + object.image.large.url if object.image.present?
12+
Rails.application.config.public_url + object.image.large.url if object.image.present?
1313
end
1414

1515
class Api::UserSerializer < ActiveModel::Serializer

app/serializers/message_serializer.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def updated_at
1515
def image_url
1616
if object.image.present?
1717
# scope is group_id
18-
"#{PUBLIC_URL}#{download_image_group_message_path(group_id: scope, id: object.id)}"
18+
"#{Rails.application.config.public_url}#{download_image_group_message_path(group_id: scope, id: object.id)}"
1919
end
2020
end
2121

@@ -25,6 +25,6 @@ def image_url
2525
attribute(:avatar)
2626

2727
def avatar
28-
PUBLIC_URL + object.user.thumb_avatar if object.user.thumb_avatar
28+
Rails.application.config.public_url + object.user.thumb_avatar if object.user.thumb_avatar
2929
end
3030
end

app/services/cafe_service.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ def self.group_cafe_shifts(date_start, date_end, shifts)
9595
month = shift.start.month
9696
day_name = I18n.t("date.day_names")[week_day].capitalize
9797
month_name = I18n.t("date.month_names")[month].capitalize
98-
unless h[:years][shift.start.year][:months][month_name][:days]["#{day_name} - #{shift.start.day}/#{shift.start.month}"].nil?
99-
h[:years][shift.start.year][:months][month_name][:days]["#{day_name} - #{shift.start.day}/#{shift.start.month}"].push(Api::CafeShiftSerializer::Index.new(shift).as_json)
100-
end
98+
h[:years][shift.start.year][:months][month_name][:days]["#{day_name} - #{shift.start.day}/#{shift.start.month}"]&.push(Api::CafeShiftSerializer::Index.new(shift).as_json)
10199
end
102100
end
103101
end

app/services/calendar_service.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def self.event(resource, locale: "sv")
3939
ical_event.created = date_time(resource.created_at.utc, tzid: "UTC")
4040
ical_event.last_modified = date_time(resource.updated_at.utc, tzid: "UTC")
4141
ical_event.url = Rails.application.routes.url_helpers.event_url(resource.id,
42-
host: PUBLIC_URL)
42+
host: Rails.application.config.public_url)
4343
ical_event.ip_class = "PUBLIC"
4444
ical_event
4545
end

app/services/meeting_service.rb

+1-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ def self.create_recurring_meeting(meeting_params, old_recurring = nil)
2323
begin
2424
RecurringMeeting.transaction do
2525
# If old recurring is specified destroy it
26-
if !old_recurring.nil?
27-
old_recurring.destroy!
28-
end
26+
old_recurring&.destroy!
2927
recurring_meeting = RecurringMeeting.new(every: every)
3028
recurring_meeting.save!
3129
meetings.each do |meeting|

app/view_objects/cafe_competition.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class CafeCompetition
2-
attr_accessor :cafe_workers, :lp, :users, :lps, :year, :years, :amount
2+
attr_accessor :cafe_workers, :lp, :users, :lps, :year, :amount
33
def initialize(lp:, year:, amount:)
44
@cafe_workers = CafeQueries.cafe_workers(lp, year)
55
@lp = lp

app/view_objects/election_view.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class ElectionView
2-
attr_reader :election, :post_count
2+
attr_reader :election
33
attr_accessor :rest_grid, :grid, :candidate, :user, :nomination
44

55
def initialize(election, candidate: nil)

app/views/election_mailer/candidate_email.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
date: l(@candidate.election.post_closing(@candidate.post)))) %>
2121
<br>
2222

23-
<%= link_to(t('.show_your_candidacies'), candidates_url(host: PUBLIC_URL), class: 'btn') %>
23+
<%= link_to(t('.show_your_candidacies'), candidates_url(host: Rails.application.config.public_url), class: 'btn') %>
2424
<br>
2525
<br>
2626

config/environments/development.rb

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Fsek::Application.configure do
2-
PUBLIC_URL = "http://localhost:3000".freeze
2+
config.public_url = "http://localhost:3000".freeze
3+
34
# Settings specified here will take precedence over those in config/application.rb.
45

56
# In the development environment your application's code is reloaded on
@@ -29,7 +30,7 @@
2930
# Don't care if the mailer can't send.
3031
# Send deprecation notices to registered listeners.
3132
config.active_support.deprecation = :notify
32-
config.action_mailer.default_url_options = {host: PUBLIC_URL}
33+
config.action_mailer.default_url_options = {host: config.public_url}
3334
config.action_mailer.delivery_method = :smtp
3435
config.action_mailer.perform_deliveries = true
3536
config.action_mailer.raise_delivery_errors = false
@@ -39,7 +40,7 @@
3940
config.action_mailer.smtp_settings = {
4041
address: "127.0.0.1",
4142
port: 1025,
42-
domain: PUBLIC_URL,
43+
domain: config.public_url,
4344
authentication: "plain",
4445
enable_starttls_auto: false
4546
}
@@ -58,8 +59,8 @@
5859
config.assets.digest = false
5960

6061
# Assets for mailers
61-
config.action_controller.asset_host = PUBLIC_URL
62-
config.action_mailer.asset_host = PUBLIC_URL
62+
config.action_controller.asset_host = config.public_url
63+
config.action_mailer.asset_host = config.public_url
6364

6465
config.action_view.raise_on_missing_translations = true
6566

@@ -75,7 +76,7 @@
7576
Bullet.add_footer = true
7677
end
7778

78-
config.action_cable.allowed_request_origins = [PUBLIC_URL, "file://", "file:///"]
79+
config.action_cable.allowed_request_origins = [config.public_url, "file://", "file:///"]
7980

8081
# Use an evented file watcher to asynchronously detect changes in source code,
8182
# routes, locales, etc. This feature depends on the listen gem.

config/environments/production.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Rails.application.configure do
2-
PUBLIC_URL = "https://fsektionen.se".freeze
2+
config.public_url = "https://fsektionen.se".freeze
33
# Settings specified here will take precedence over those in config/application.rb.
44

55
# Code is not reloaded between requests.
@@ -73,9 +73,9 @@
7373
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
7474
# config.action_mailer.raise_delivery_errors = false
7575
config.active_support.deprecation = :notify
76-
config.action_mailer.asset_host = PUBLIC_URL
76+
config.action_mailer.asset_host = config.public_url
7777
config.action_mailer.default charset: "utf-8"
78-
config.action_mailer.default_url_options = {host: PUBLIC_URL}
78+
config.action_mailer.default_url_options = {host: config.public_url}
7979
config.action_mailer.delivery_method = :smtp
8080
config.action_mailer.perform_deliveries = true
8181
config.action_mailer.raise_delivery_errors = true
@@ -106,5 +106,5 @@
106106
# Do not dump schema after migrations.
107107
config.active_record.dump_schema_after_migration = false
108108

109-
config.action_cable.allowed_request_origins = [PUBLIC_URL, "file://", "file:///"]
109+
config.action_cable.allowed_request_origins = [config.public_url, "file://", "file:///"]
110110
end

config/environments/staging.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Rails.application.configure do
2-
PUBLIC_URL = "https://stage.fsektionen.se".freeze
2+
config.public_url = "https://stage.fsektionen.se".freeze
33
# Settings specified here will take precedence over those in config/application.rb.
44

55
# Code is not reloaded between requests.
@@ -60,9 +60,9 @@
6060
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
6161
# config.action_mailer.raise_delivery_errors = false
6262
config.active_support.deprecation = :notify
63-
config.action_mailer.asset_host = PUBLIC_URL
63+
config.action_mailer.asset_host = config.public_url
6464
config.action_mailer.default charset: "utf-8"
65-
config.action_mailer.default_url_options = {host: PUBLIC_URL}
65+
config.action_mailer.default_url_options = {host: config.public_url}
6666
config.action_mailer.delivery_method = :smtp
6767
config.action_mailer.perform_deliveries = true
6868
config.action_mailer.raise_delivery_errors = true
@@ -93,5 +93,5 @@
9393
# Do not dump schema after migrations.
9494
config.active_record.dump_schema_after_migration = false
9595

96-
config.action_cable.allowed_request_origins = [PUBLIC_URL, "file://", "file:///"]
96+
config.action_cable.allowed_request_origins = [config.public_url, "file://", "file:///"]
9797
end

config/environments/test.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Fsek::Application.configure do
2-
PUBLIC_URL = "http://localhost:3000".freeze
2+
config.public_url = "https://fsektionen.se".freeze
33
# Settings specified here will take precedence over those in config/application.rb.
44

55
# The test environment is used exclusively to run your application's
@@ -38,9 +38,9 @@
3838
# Print deprecation notices to the stderr.
3939
config.active_support.deprecation = :stderr
4040

41-
config.action_controller.asset_host = PUBLIC_URL
42-
config.action_mailer.default_url_options = {host: PUBLIC_URL}
43-
config.action_mailer.asset_host = PUBLIC_URL
41+
config.action_controller.asset_host = config.public_url
42+
config.action_mailer.default_url_options = {host: config.public_url}
43+
config.action_mailer.asset_host = config.public_url
4444

4545
config.action_view.raise_on_missing_translations = true
4646
end

config/initializers/action_cable_config.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module ActionCableConfig
33
def self.[](key)
44
unless @config
55
template = ERB.new(File.read(Rails.root + "config/cable.yml"))
6-
@config = YAML.load(template.result(binding))[Rails.env].symbolize_keys
6+
# TODO: Use safe_load switched to ruby 2.6
7+
@config = YAML.load(template.result(binding))[Rails.env].symbolize_keys # rubocop:disable Security/YAMLLoad
78
end
89

910
@config[key]

config/initializers/carrierwave.rb

+2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
config.enable_processing = false
55
end
66

7+
# rubocop:disable Lint/Void
78
AttachedImageUploader
89
DocumentUploader
910
ImageUploader
11+
# rubocop:enable Lint/Void
1012

1113
CarrierWave::Uploader::Base.descendants.each do |klass|
1214
next if klass.anonymous?

config/initializers/rpush.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# Path to log file. Relative to current directory unless absolute.
2121
config.log_file = "log/rpush.log"
2222

23-
config.log_level = defined?(Rails) && Rails.logger ? Rails.logger.level : ::Logger::Severity::INFO
23+
config.log_level = defined?(Rails) && Rails.logger ? Rails.logger.level : ::Logger::Severity::INFO # rubocop:disable Lint/RequireParentheses
2424

2525
# Define a custom logger.
2626
# config.logger = MyLogger.new

config/puma.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
# the maximum value specified for Puma. Default is set to 5 threads for minimum
55
# and maximum; this matches the default thread size of Active Record.
66
#
7-
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }
7+
threads_count = ENV.fetch("RAILS_MAX_THREADS", 5)
88
threads threads_count, threads_count
99

1010
# Specifies the `port` that Puma will listen on to receive requests; default is 3000.
1111
#
12-
port ENV.fetch("PORT") { 3000 }
12+
port ENV.fetch("PORT", 3000)
1313

1414
# Specifies the `environment` that Puma will run in.
1515
#
16-
environment ENV.fetch("RAILS_ENV") { "development" }
16+
environment ENV.fetch("RAILS_ENV", "development")
1717

1818
# Specifies the number of `workers` to boot in clustered mode.
1919
# Workers are forked webserver processes. If using threads and workers together

0 commit comments

Comments
 (0)