Skip to content

Commit

Permalink
Run rubocop autocorrections
Browse files Browse the repository at this point in the history
  • Loading branch information
julianguyen committed Oct 14, 2023
1 parent c7a01a5 commit 635b264
Show file tree
Hide file tree
Showing 69 changed files with 200 additions and 235 deletions.
42 changes: 20 additions & 22 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,28 @@ end

desc 'Automate the Config Setup for New Environments'
task setup_workspace: :environment do
begin
SECRETS = {
SECRET_KEY_BASE: generate_secret,
DEVISE_SECRET_KEY: generate_secret
}.freeze

%w[development test].each do |environment|
example = Rails.root.join('config', 'env', "#{environment}.example.env")
target = Rails.root.join('config', 'env', "#{environment}.env")
FileUtils.cp(example, target)

# insert the secrets into the file
content = File.read(target)
%w[SECRET_KEY_BASE DEVISE_SECRET_KEY].each do |key|
content.sub!(%(#{key}=""), %(#{key}="#{SECRETS[key.to_sym]}"))
end
File.write(target, content)
SECRETS = {
SECRET_KEY_BASE: generate_secret,
DEVISE_SECRET_KEY: generate_secret
}.freeze

%w[development test].each do |environment|
example = Rails.root.join('config', 'env', "#{environment}.example.env")
target = Rails.root.join('config', 'env', "#{environment}.env")
FileUtils.cp(example, target)

# insert the secrets into the file
content = File.read(target)
%w[SECRET_KEY_BASE DEVISE_SECRET_KEY].each do |key|
content.sub!(%(#{key}=""), %(#{key}="#{SECRETS[key.to_sym]}"))
end

puts "Workspace setup completed successfully 🎉"
rescue StandardError => e
puts "Exception Occurred #{e.class}. Message: #{e.message}. Backtrace: \n #{e.backtrace.join("\n")}"
Rails.logger.error "Exception Occurred #{e.class}. Message: #{e.message}. Backtrace: \n #{e.backtrace.join("\n")}"
File.write(target, content)
end

puts 'Workspace setup completed successfully 🎉'
rescue StandardError => e
puts "Exception Occurred #{e.class}. Message: #{e.message}. Backtrace: \n #{e.backtrace.join("\n")}"
Rails.logger.error "Exception Occurred #{e.class}. Message: #{e.message}. Backtrace: \n #{e.backtrace.join("\n")}"
end

# Run the secret task, grab the output, strip the new lines
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/allies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ def index

def add
AllyshipCreator.perform(ally_id: params[:ally_id],
current_user: current_user)
current_user:)
redirect_to_path(allies_path)
end

def remove
user_id = current_user.id
ally_id = params[:ally_id].to_i
Allyship.where(user_id: user_id, ally_id: ally_id).destroy_all
Allyship.where(user_id:, ally_id:).destroy_all
redirect_to_path(allies_path)
end
end
8 changes: 3 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class ApplicationController < ActionController::Base

private

def with_timezone
def with_timezone(&)
timezone = Time.find_zone(cookies[:timezone])
Time.use_zone(timezone) { yield }
Time.use_zone(timezone, &)
end

def set_locale
Expand Down Expand Up @@ -64,9 +64,7 @@ def configure_for_accept_invitation
end

def after_sign_in_path_for(resource)
if resource.respond_to?(:pwned?) && resource.pwned?
cookies[:pwned] = { value: true, expires: Time.current + 10.minutes }
end
cookies[:pwned] = { value: true, expires: 10.minutes.from_now } if resource.respond_to?(:pwned?) && resource.pwned?

super
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def delete

def remove_meeting_notification!(comment_id)
CommentNotificationsService.remove(
comment_id: comment_id,
comment_id:,
model_name: 'Meeting'
)
end
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/concerns/moments_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def saving_as_draft?

def empty_array_for(*symbols)
symbols.each do |symbol|
if moment_params[symbol].nil? && @moment.has_attribute?(symbol)
@moment[symbol] = []
end
@moment[symbol] = [] if moment_params[symbol].nil? && @moment.has_attribute?(symbol)
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/concerns/shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def format_success(format, model_object, is_update)
path = show_path(model_object)
format.html { redirect_to path }
status = is_update ? :ok : :created
format.json { render :show, status: status, location: model_object }
format.json { render :show, status:, location: model_object }
end

def format_failure(format, model_object, is_update)
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/concerns/strategies_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def render_errors(strategy)

def empty_array_for(*symbols)
symbols.each do |symbol|
if strategy_params[symbol].nil? && @strategy.has_attribute?(symbol)
@strategy[symbol] = []
end
@strategy[symbol] = [] if strategy_params[symbol].nil? && @strategy.has_attribute?(symbol)
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/groups/memberships_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create

flash[:notice] = t('groups.join.success')
redirect_to_group
rescue
rescue StandardError
flash[:alert] = t('groups.join.group_not_exists')
redirect_to groups_path
end
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def index
# GET /groups/1
# GET /groups/1.json
def show
if @group.members.include? current_user
@meetings = @group.meetings.includes(:leaders)
end
@meetings = @group.meetings.includes(:leaders) if @group.members.include? current_user

@page_new = t('meetings.new') if @group.led_by?(current_user)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/medications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def add_refill(medication)
dosage = @medication&.dosage || medication[:dosage]
no_of_days = total.to_i / dosage.to_i
no_of_weeks = no_of_days.to_i / weekly_dosage.length
days = 7 * no_of_weeks + (no_of_days % weekly_dosage.length)
days = (7 * no_of_weeks) + (no_of_days % weekly_dosage.length)
Time.zone.now.strftime('%d/%m/%Y').to_date + days - 1
end

Expand Down
12 changes: 6 additions & 6 deletions app/controllers/meetings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ def leave
# Cannot leave When you are the only leader
if meeting.led_by?(current_user) && meeting.leaders.count == 1
redirect_to(group_path(meeting.group_id),
alert: t('meetings.leave.error'))
alert: t('.error'))
else
# Remove user from meeting
meeting.meeting_members.find_by(user_id: current_user.id).destroy
redirect_to(group_path(meeting.group_id),
notice: t('meetings.leave.success', meeting: meeting.name))
notice: t('.success', meeting: meeting.name))
end
end

Expand Down Expand Up @@ -107,10 +107,10 @@ def meeting_params

def send_notification(meeting, members, type)
MeetingNotificationsService.handle_members(
current_user: current_user,
meeting: meeting,
type: type,
members: members
current_user:,
meeting:,
type:,
members:
)
end

Expand Down
6 changes: 2 additions & 4 deletions app/controllers/moments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def show
show_with_comments(@moment)
resources_data = get_resources_data(@moment, current_user)
@resources = ResourceRecommendations.new(
moment: @moment, current_user: current_user
moment: @moment, current_user:
).call
@show_crisis_prevention = resources_data[:show_crisis_prevention]
@resources_tags = resources_data[:tags]
Expand All @@ -41,9 +41,7 @@ def new

# GET /moments/1/edit
def edit
unless @moment.user_id == current_user.id
redirect_to_path(moment_path(@moment))
end
redirect_to_path(moment_path(@moment)) unless @moment.user_id == current_user.id
set_association_variables!
end

Expand Down
6 changes: 3 additions & 3 deletions app/controllers/profile_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def remove_ban
private

def update_and_email(user, banned)
user.update(banned: banned)
user.update(banned:)
if banned
BannedMailer.add_ban_email(user).deliver_now
else
Expand All @@ -53,8 +53,8 @@ def ban(banned)

def notice_or_alert(user, notice)
name = user&.name || params[:user_id]
return { notice: t("reports.#{notice}", name: name) } if user.present?
return { notice: t("reports.#{notice}", name:) } if user.present?

{ alert: t("reports.#{notice}_error", name: name) }
{ alert: t("reports.#{notice}_error", name:) }
end
end
2 changes: 1 addition & 1 deletion app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def posts
private

def search_by_email(email)
User.where(email: email)
User.where(email:)
.where.not(id: current_user.id)
.where.not(banned: true)
end
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/secret_shares_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
class SecretSharesController < ApplicationController
skip_before_action :if_not_signed_in, only: [:show]

def show
@moment = Moment.find_secret_share!(params[:id])
@page_author = User.find(@moment.user_id)
render 'moments/show'
end

def create
# Authorisation check will automatically raise ActiveRecord::RecordNotFound
moment = Moment.where(user: current_user).friendly.find(params[:moment])
Expand All @@ -13,12 +19,6 @@ def create
redirect_to moment_path(moment, anchor: 'secretShare')
end

def show
@moment = Moment.find_secret_share!(params[:id])
@page_author = User.find(@moment.user_id)
render 'moments/show'
end

def destroy
moment = Moment.find_by!(user: current_user, id: params[:id])
moment.update!(secret_share_identifier: nil)
Expand Down
8 changes: 3 additions & 5 deletions app/controllers/strategies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ def new

# GET /strategies/1/edit
def edit
unless @strategy.user_id == current_user.id
redirect_to_path(strategy_path(@strategy))
end
redirect_to_path(strategy_path(@strategy)) unless @strategy.user_id == current_user.id
@viewers = current_user.allies_by_status(:accepted)
@categories = current_user.categories.is_visible
.or(Category.where(id: @strategy.category_ids))
Expand All @@ -75,7 +73,7 @@ def premade
strategy = premade_strategy
respond_to do |format|
if strategy.save
PerformStrategyReminder.create!(strategy: strategy, active: false)
PerformStrategyReminder.create!(strategy:, active: false)
format.json { head :no_content }
else
format.json { render_errors(strategy) }
Expand Down Expand Up @@ -124,7 +122,7 @@ def set_strategy
end

def quick_create_params(viewers)
{ user_id: current_user.id, comment: true, viewers: viewers, visible: true,
{ user_id: current_user.id, comment: true, viewers:, visible: true,
description: params[:strategy][:description], published_at: Time.zone.now,
category: params[:strategy][:category], name: params[:strategy][:name] }
end
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/users/invitations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ def update
AllyshipCreator.perform(ally_id: resource.id,
current_user: resource.invited_by)
if resource.class.allow_insecure_sign_in_after_accept
# rubocop:disable Layout/LineLength
flash_message = resource.active_for_authentication? ? :updated : :updated_not_active
# rubocop:enable Layout/LineLength
set_flash_message :notice, flash_message if is_flashing_format?
sign_in(resource_name, resource)
respond_with resource, location: after_accept_path_for(resource)
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/users/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ class ReportsController < ApplicationController

def submit_request
status, response = submit_request_helper(current_user)
render json: response, status: status
render json: response, status:
end

def fetch_request_status
status, response = fetch_request_status_helper(current_user,
params[:request_id])
render json: response, status: status
render json: response, status:
end

def download_data
status, response = download_data_helper(current_user,
params[:request_id])
if status != 200
render json: response, status: status
else
if status == 200
send_file(response, status: 200)
else
render(json: response, status:)
end
end
end
Expand Down
43 changes: 22 additions & 21 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,33 @@ def sign_in_path?

def page_title
t('app_name') +
if sign_in_path?
" | " + t('account.sign_in')
elsif join_path?
" | " + t('account.sign_up')
elsif forgot_password_path?
" | " + t('account.forgot_password')
elsif update_account_path?
" | " + t('account.singular')
elsif current_page?(root_path)
" | " + t('app_description')
elsif send_ally_invitation_path?
" | " + t('devise.invitations.new.header')
elsif ally_accept_invitation_path?
" | " + t('devise.invitations.edit.header')
elsif reset_password_path?
" | " + t('layouts.title.reset_password')
elsif new_user_confirmation_path?
" | " + t('devise.confirmations.resend_confirmation')
else
" | " + title_content
end
if sign_in_path?
' | ' + t('account.sign_in')
elsif join_path?
' | ' + t('account.sign_up')
elsif forgot_password_path?
' | ' + t('account.forgot_password')
elsif update_account_path?
' | ' + t('account.singular')
elsif current_page?(root_path)
' | ' + t('app_description')
elsif send_ally_invitation_path?
' | ' + t('devise.invitations.new.header')
elsif ally_accept_invitation_path?
' | ' + t('devise.invitations.edit.header')
elsif reset_password_path?
' | ' + t('layouts.title.reset_password')
elsif new_user_confirmation_path?
' | ' + t('devise.confirmations.resend_confirmation')
else
' | ' + title_content
end
end

def title_content
content_for(:title) || 'a community for mental health experiences'
end

def join_path?
path = new_user_registration_path
devise_page?(path, 'registrations', 'create') ||
Expand Down
Loading

0 comments on commit 635b264

Please sign in to comment.