Skip to content

Commit

Permalink
Rubocop autofixes 🤖
Browse files Browse the repository at this point in the history
  • Loading branch information
archonic committed Sep 30, 2023
1 parent a5d89de commit 98c3f54
Show file tree
Hide file tree
Showing 559 changed files with 2,859 additions and 1,854 deletions.
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

Expand Down
55 changes: 28 additions & 27 deletions app/controllers/account/appointments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Account
class AppointmentsController < BaseController
include AppointmentSlots
Expand Down Expand Up @@ -62,39 +64,38 @@ def update

def destroy
@appointment.destroy
redirect_to account_appointments_path, flash: {success: "Appointment cancelled."}
redirect_to account_appointments_path, flash: { success: "Appointment cancelled." }
end

private
def appointment_params
form_params = params.require(:appointment).permit(:comment, :time_range_string, hold_ids: [], loan_ids: [])

{
holds: @member.holds.where(id: form_params[:hold_ids]),
loans: @member.loans.where(id: form_params[:loan_ids]),
comment: form_params[:comment],
time_range_string: form_params[:time_range_string],
member_updating: true
}
end

def appointment_params
form_params = params.require(:appointment).permit(:comment, :time_range_string, hold_ids: [], loan_ids: [])

{
holds: @member.holds.where(id: form_params[:hold_ids]),
loans: @member.loans.where(id: form_params[:loan_ids]),
comment: form_params[:comment],
time_range_string: form_params[:time_range_string],
member_updating: true
}
end

def load_holds_and_loans
@holds = Hold.active.includes(member: {appointments: :holds}).where(member: @member)
@loans = @member.loans.includes(:item, member: {appointments: :loans}).checked_out
end
def load_holds_and_loans
@holds = Hold.active.includes(member: { appointments: :holds }).where(member: @member)
@loans = @member.loans.includes(:item, member: { appointments: :loans }).checked_out
end

def merge_simultaneous_appointments
simultaneous_appointment = @member.appointments.simultaneous(@appointment).first
if simultaneous_appointment
simultaneous_appointment.merge!(@appointment)
true
def merge_simultaneous_appointments
simultaneous_appointment = @member.appointments.simultaneous(@appointment).first
if simultaneous_appointment
simultaneous_appointment.merge!(@appointment)
true
end
end
end

def load_appointment_for_editing
@appointment = current_member.appointments.find(params[:id])
redirect_to account_appointments_path, alert: "Completed appointments can't be changed" if @appointment.completed?
end
def load_appointment_for_editing
@appointment = current_member.appointments.find(params[:id])
redirect_to account_appointments_path, alert: "Completed appointments can't be changed" if @appointment.completed?
end
end
end
2 changes: 2 additions & 0 deletions app/controllers/account/base_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Account
class BaseController < ApplicationController
before_action :authenticate_user!
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/account/holds_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Account
class HoldsController < BaseController
def index
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/account/home_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Account
class HomeController < BaseController
def index
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/account/loans_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Account
class LoansController < BaseController
def index
Expand Down
33 changes: 17 additions & 16 deletions app/controllers/account/members_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Account
class MembersController < ApplicationController
def show
Expand All @@ -20,21 +22,20 @@ def update
end

private

def member_params
params.require(:member).permit(:full_name,
:preferred_name,
:email,
:phone_number,
:address1,
:address2,
:postal_code,
:desires,
:reminders_via_email,
:reminders_via_text,
:receive_newsletter,
:volunteer_interest,
pronouns: [])
end
def member_params
params.require(:member).permit(:full_name,
:preferred_name,
:email,
:phone_number,
:address1,
:address2,
:postal_code,
:desires,
:reminders_via_email,
:reminders_via_text,
:receive_newsletter,
:volunteer_interest,
pronouns: [])
end
end
end
9 changes: 5 additions & 4 deletions app/controllers/account/passwords_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Account
class PasswordsController < BaseController
def edit
Expand All @@ -15,9 +17,8 @@ def update
end

private

def user_params
params.require(:user).permit(:current_password, :password, :password_confirmation)
end
def user_params
params.require(:user).permit(:current_password, :password, :password_confirmation)
end
end
end
6 changes: 4 additions & 2 deletions app/controllers/account/renewal_requests_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Account
class RenewalRequestsController < BaseController
def create
Expand All @@ -10,9 +12,9 @@ def create
@renewal_request = RenewalRequest.new(loan: @loan)

flash_message = if @renewal_request.save
{success: "Renewal requested. We'll e-mail you an update."}
{ success: "Renewal requested. We'll e-mail you an update." }
else
{error: "Something went wrong!"}
{ error: "Something went wrong!" }
end

redirect_to account_loans_path, flash: flash_message
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/account/renewals_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Account
class RenewalsController < BaseController
include Lending
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/admin/appointment_checkins_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Admin
class AppointmentCheckinsController < BaseController
before_action :are_appointments_enabled?
Expand Down
39 changes: 20 additions & 19 deletions app/controllers/admin/appointment_checkouts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Admin
class AppointmentCheckoutsController < BaseController
include Lending
Expand All @@ -6,34 +8,33 @@ class AppointmentCheckoutsController < BaseController

def create
create_loans_for_holds
redirect_to admin_appointment_path(appointment), flash: {success: "#{pluralize(checked_out_item_count, "Item")} checked-out."}
redirect_to admin_appointment_path(appointment), flash: { success: "#{pluralize(checked_out_item_count, "Item")} checked-out." }
end

private
attr_accessor :new_loans

attr_accessor :new_loans

delegate :pluralize, to: "ActionController::Base.helpers", private: true
delegate :member, to: :appointment
delegate :pluralize, to: "ActionController::Base.helpers", private: true
delegate :member, to: :appointment

def checked_out_item_count
new_loans&.count&.to_i
end
def checked_out_item_count
new_loans&.count&.to_i
end

def holds
@holds ||= appointment.holds.active.where(id: params[:hold_ids])
end
def holds
@holds ||= appointment.holds.active.where(id: params[:hold_ids])
end

def appointment
@appointment ||= Appointment.find(params[:appointment_id])
end
def appointment
@appointment ||= Appointment.find(params[:appointment_id])
end

def create_loans_for_holds
self.new_loans = member.transaction do
holds.map do |hold|
create_loan_from_hold(hold)
def create_loans_for_holds
self.new_loans = member.transaction do
holds.map do |hold|
create_loan_from_hold(hold)
end
end
end
end
end
end
6 changes: 4 additions & 2 deletions app/controllers/admin/appointment_completions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Admin
class AppointmentCompletionsController < BaseController
before_action :are_appointments_enabled?
Expand All @@ -7,13 +9,13 @@ class AppointmentCompletionsController < BaseController
def create
@appointment = Appointment.find(params[:appointment_id])
@appointment.update!(completed_at: Time.current, staff_updating: true)
render_to_portal("admin/appointments/appointment", table_row: true, locals: {appointment: @appointment})
render_to_portal("admin/appointments/appointment", table_row: true, locals: { appointment: @appointment })
end

def destroy
@appointment = Appointment.find(params[:appointment_id])
@appointment.update!(completed_at: nil, staff_updating: true)
render_to_portal("admin/appointments/appointment", table_row: true, locals: {appointment: @appointment})
render_to_portal("admin/appointments/appointment", table_row: true, locals: { appointment: @appointment })
end
end
end
75 changes: 38 additions & 37 deletions app/controllers/admin/appointment_holds_controller.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Admin
class AppointmentHoldsController < ApplicationController
before_action :are_appointments_enabled?
Expand All @@ -9,57 +11,56 @@ def create

def destroy
remove_appointment_hold
redirect_to admin_appointment_path(appointment), flash: {success: "Item removed from appointment."}
redirect_to admin_appointment_path(appointment), flash: { success: "Item removed from appointment." }
end

private
def remove_appointment_hold
@remove_appointment_hold ||= appointment.appointment_holds.find_by(hold_id: params[:id]).destroy

def remove_appointment_hold
@remove_appointment_hold ||= appointment.appointment_holds.find_by(hold_id: params[:id]).destroy

if params[:cancel_hold]
Hold.find(params[:id]).destroy
if params[:cancel_hold]
Hold.find(params[:id]).destroy
end
end
end

def add_new_appointment_hold
return if item_to_add.blank? ||
item_to_add.allow_one_holds_per_member? &&
appointment.appointment_holds.joins(:hold).exists?(holds: {item: item_to_add})
def add_new_appointment_hold
return if item_to_add.blank? ||
item_to_add.allow_one_holds_per_member? &&
appointment.appointment_holds.joins(:hold).exists?(holds: { item: item_to_add })

new_appointment_hold.save
end
new_appointment_hold.save
end

def create_flash_message
if new_appointment_hold&.persisted?
{success: "Item added to appointment check-outs."}
else
{error: "Unable to add item to appointment check-outs."}
def create_flash_message
if new_appointment_hold&.persisted?
{ success: "Item added to appointment check-outs." }
else
{ error: "Unable to add item to appointment check-outs." }
end
end
end

def new_appointment_hold
return if item_to_add.blank?
def new_appointment_hold
return if item_to_add.blank?

@new_appointment_hold ||= appointment.appointment_holds.new(
hold: hold_for_item_to_add
)
end
@new_appointment_hold ||= appointment.appointment_holds.new(
hold: hold_for_item_to_add
)
end

def hold_for_item_to_add
@item_to_add_hold ||= if item_to_add.allow_multiple_holds_per_member?
appointment.member.holds.new(item: item_to_add, creator: current_user)
elsif item_to_add.available?
appointment.member.active_holds.find_or_initialize_by(item: item_to_add, creator: current_user)
def hold_for_item_to_add
@item_to_add_hold ||= if item_to_add.allow_multiple_holds_per_member?
appointment.member.holds.new(item: item_to_add, creator: current_user)
elsif item_to_add.available?
appointment.member.active_holds.find_or_initialize_by(item: item_to_add, creator: current_user)
end
end
end

def item_to_add
Item.find_by_complete_number(params.require(:appointment_hold)[:item_id].to_s)
end
def item_to_add
Item.find_by_complete_number(params.require(:appointment_hold)[:item_id].to_s)
end

def appointment
@appointment ||= Appointment.find(params[:appointment_id])
end
def appointment
@appointment ||= Appointment.find(params[:appointment_id])
end
end
end
Loading

0 comments on commit 98c3f54

Please sign in to comment.