Run Rubocop autocorrect on app/models

This commit is contained in:
Manuel Bustillo 2024-12-28 18:13:57 +01:00
parent 2fc8a6340b
commit 19dcb551fa
10 changed files with 35 additions and 9 deletions

View File

@ -18,4 +18,6 @@ RSpec/ExampleLength:
Metrics/ModuleLength: Metrics/ModuleLength:
Enabled: false Enabled: false
RSpec/MultipleMemoizedHelpers: RSpec/MultipleMemoizedHelpers:
Enabled: false
Style/Documentation:
Enabled: false Enabled: false

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
class ApplicationRecord < ActiveRecord::Base class ApplicationRecord < ActiveRecord::Base

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
# == Schema Information # == Schema Information

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
# == Schema Information # == Schema Information
@ -31,7 +33,7 @@ class Group < ApplicationRecord
validates :name, uniqueness: true validates :name, uniqueness: true
validates :name, :order, presence: true validates :name, :order, presence: true
has_many :children, class_name: 'Group', foreign_key: 'parent_id' has_many :children, class_name: 'Group', foreign_key: 'parent_id', dependent: :nullify, inverse_of: :parent
belongs_to :parent, class_name: 'Group', optional: true belongs_to :parent, class_name: 'Group', optional: true
before_create :set_color before_create :set_color
@ -41,10 +43,7 @@ class Group < ApplicationRecord
has_many :guests, dependent: :nullify has_many :guests, dependent: :nullify
def colorize_children(generation = 1) def colorize_children(generation = 1)
derived_colors = generation == 1 ? color.paint.palette.analogous(size: children.count) : color.paint.palette.decreasing_saturation children.zip(palette(generation)) do |child, raw_color|
children.zip(derived_colors) do |child, raw_color|
final_color = raw_color.paint final_color = raw_color.paint
final_color.brighten(60) if final_color.dark? final_color.brighten(60) if final_color.dark?
@ -53,13 +52,21 @@ class Group < ApplicationRecord
child.colorize_children(generation + 1) child.colorize_children(generation + 1)
end end
end end
def affinities def affinities
GroupAffinity.where(group_a_id: id).or(GroupAffinity.where(group_b_id: id)) GroupAffinity.where(group_a_id: id).or(GroupAffinity.where(group_b_id: id))
end end
private private
def palette(generation)
if generation == 1
color.paint.palette.analogous(size: children.count)
else
color.paint.palette.decreasing_saturation
end
end
def set_color def set_color
return if color.present? return if color.present?

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
# == Schema Information # == Schema Information
@ -30,7 +32,8 @@ class GroupAffinity < ApplicationRecord
belongs_to :group_a, class_name: 'Group' belongs_to :group_a, class_name: 'Group'
belongs_to :group_b, class_name: 'Group' belongs_to :group_b, class_name: 'Group'
validates :discomfort, numericality: { greater_than_or_equal_to: MIN_DISCOMFORT, less_than_or_equal_to: MAX_DISCOMFORT } validates :discomfort,
numericality: { greater_than_or_equal_to: MIN_DISCOMFORT, less_than_or_equal_to: MAX_DISCOMFORT }
def another_group(group) def another_group(group)
return nil if group != group_a && group != group_b return nil if group != group_a && group != group_b

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
# == Schema Information # == Schema Information
@ -39,8 +41,8 @@ class Guest < ApplicationRecord
scope :potential, -> { where.not(status: %i[declined considered]) } scope :potential, -> { where.not(status: %i[declined considered]) }
after_save :recalculate_simulations, if: :saved_change_to_status?
after_destroy :recalculate_simulations after_destroy :recalculate_simulations
after_save :recalculate_simulations, if: :saved_change_to_status?
has_many :seats, dependent: :delete_all has_many :seats, dependent: :delete_all

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
# == Schema Information # == Schema Information

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
# == Schema Information # == Schema Information
@ -21,7 +23,7 @@
# #
class TablesArrangement < ApplicationRecord class TablesArrangement < ApplicationRecord
acts_as_tenant :wedding acts_as_tenant :wedding
has_many :seats has_many :seats, dependent: :delete_all
has_many :guests, through: :seats has_many :guests, through: :seats
before_create :assign_name before_create :assign_name

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
# == Schema Information # == Schema Information

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
# Copyright (C) 2024 Manuel Bustillo # Copyright (C) 2024 Manuel Bustillo
# == Schema Information # == Schema Information