Files
grecia/app/components/admin/machine_learning/setting_component.rb
Javi Martín 0ca94e5443 Add and apply Rails/FindByOrAssignmentMemoization rule
This rule was added in rubocop-rails 2.33.

At first, I wasn't very fond of this rule. It made the code less
readable even if it improved performace in some cases.

Then I realized that in the `Admin::MachineLearning::SettingComponent`
we were using `find_by` when we should be using `find_by!` instead, and
we detected that thanks to this rule.

So, only for that reason, I'm adding this rule, but I'm fine if we
remove it.
2025-11-05 11:51:23 +01:00

26 lines
496 B
Ruby

class Admin::MachineLearning::SettingComponent < ApplicationComponent
attr_reader :kind
def initialize(kind)
@kind = kind
end
private
def setting
@setting ||= Setting.find_by!(key: "machine_learning.#{kind}")
end
def ml_info
@ml_info ||= MachineLearningInfo.for(kind)
end
def filenames
::MachineLearning.data_output_files[ml_info.kind.to_sym].sort
end
def data_path(filename)
::MachineLearning.data_path(filename)
end
end