From 19dcb551fa771399f78086e57e05f34435b40305 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sat, 28 Dec 2024 18:13:57 +0100 Subject: [PATCH] Run Rubocop autocorrect on app/models --- .rubocop.yml | 2 ++ app/models/application_record.rb | 2 ++ app/models/expense.rb | 2 ++ app/models/group.rb | 19 +++++++++++++------ app/models/group_affinity.rb | 5 ++++- app/models/guest.rb | 4 +++- app/models/seat.rb | 2 ++ app/models/tables_arrangement.rb | 4 +++- app/models/user.rb | 2 ++ app/models/wedding.rb | 2 ++ 10 files changed, 35 insertions(+), 9 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index b62b4ea..049b22d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -18,4 +18,6 @@ RSpec/ExampleLength: Metrics/ModuleLength: Enabled: false RSpec/MultipleMemoizedHelpers: + Enabled: false +Style/Documentation: Enabled: false \ No newline at end of file diff --git a/app/models/application_record.rb b/app/models/application_record.rb index e93781d..60a445b 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright (C) 2024 Manuel Bustillo class ApplicationRecord < ActiveRecord::Base diff --git a/app/models/expense.rb b/app/models/expense.rb index 5601c30..5be0315 100644 --- a/app/models/expense.rb +++ b/app/models/expense.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright (C) 2024 Manuel Bustillo # == Schema Information diff --git a/app/models/group.rb b/app/models/group.rb index 6552214..0a2c62a 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright (C) 2024 Manuel Bustillo # == Schema Information @@ -31,7 +33,7 @@ class Group < ApplicationRecord validates :name, uniqueness: 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 before_create :set_color @@ -41,10 +43,7 @@ class Group < ApplicationRecord has_many :guests, dependent: :nullify def colorize_children(generation = 1) - derived_colors = generation == 1 ? color.paint.palette.analogous(size: children.count) : color.paint.palette.decreasing_saturation - - children.zip(derived_colors) do |child, raw_color| - + children.zip(palette(generation)) do |child, raw_color| final_color = raw_color.paint final_color.brighten(60) if final_color.dark? @@ -53,13 +52,21 @@ class Group < ApplicationRecord child.colorize_children(generation + 1) end end - + def affinities GroupAffinity.where(group_a_id: id).or(GroupAffinity.where(group_b_id: id)) end 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 return if color.present? diff --git a/app/models/group_affinity.rb b/app/models/group_affinity.rb index 31e1503..d203589 100644 --- a/app/models/group_affinity.rb +++ b/app/models/group_affinity.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright (C) 2024 Manuel Bustillo # == Schema Information @@ -30,7 +32,8 @@ class GroupAffinity < ApplicationRecord belongs_to :group_a, 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) return nil if group != group_a && group != group_b diff --git a/app/models/guest.rb b/app/models/guest.rb index a0a2992..ed5254e 100644 --- a/app/models/guest.rb +++ b/app/models/guest.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright (C) 2024 Manuel Bustillo # == Schema Information @@ -39,8 +41,8 @@ class Guest < ApplicationRecord scope :potential, -> { where.not(status: %i[declined considered]) } - after_save :recalculate_simulations, if: :saved_change_to_status? after_destroy :recalculate_simulations + after_save :recalculate_simulations, if: :saved_change_to_status? has_many :seats, dependent: :delete_all diff --git a/app/models/seat.rb b/app/models/seat.rb index 3f13629..c4dcefe 100644 --- a/app/models/seat.rb +++ b/app/models/seat.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright (C) 2024 Manuel Bustillo # == Schema Information diff --git a/app/models/tables_arrangement.rb b/app/models/tables_arrangement.rb index 3080e49..2e11c3a 100644 --- a/app/models/tables_arrangement.rb +++ b/app/models/tables_arrangement.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright (C) 2024 Manuel Bustillo # == Schema Information @@ -21,7 +23,7 @@ # class TablesArrangement < ApplicationRecord acts_as_tenant :wedding - has_many :seats + has_many :seats, dependent: :delete_all has_many :guests, through: :seats before_create :assign_name diff --git a/app/models/user.rb b/app/models/user.rb index 43c3a9e..80cbf28 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright (C) 2024 Manuel Bustillo # == Schema Information diff --git a/app/models/wedding.rb b/app/models/wedding.rb index 125c58e..da4a50c 100644 --- a/app/models/wedding.rb +++ b/app/models/wedding.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Copyright (C) 2024 Manuel Bustillo # == Schema Information