Run Rubocop autocorrect on app/models
This commit is contained in:
parent
2fc8a6340b
commit
19dcb551fa
@ -18,4 +18,6 @@ RSpec/ExampleLength:
|
||||
Metrics/ModuleLength:
|
||||
Enabled: false
|
||||
RSpec/MultipleMemoizedHelpers:
|
||||
Enabled: false
|
||||
Style/Documentation:
|
||||
Enabled: false
|
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Copyright (C) 2024 Manuel Bustillo
|
||||
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
|
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Copyright (C) 2024 Manuel Bustillo
|
||||
|
||||
# == Schema Information
|
||||
|
@ -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?
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Copyright (C) 2024 Manuel Bustillo
|
||||
|
||||
# == Schema Information
|
||||
|
@ -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
|
||||
|
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Copyright (C) 2024 Manuel Bustillo
|
||||
|
||||
# == Schema Information
|
||||
|
@ -1,3 +1,5 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Copyright (C) 2024 Manuel Bustillo
|
||||
|
||||
# == Schema Information
|
||||
|
Loading…
x
Reference in New Issue
Block a user