Apply Style/ClassVars rubocop rule
Class variables in Ruby are not the same as instance variables of a class. They're particularly tricky when it comes to inheritance and modules. In the case of the Measurable module, for example, using a class variable will make all classes including the Measurable module share the same value. However, that's not what we want; we want the variable to be different for every class. And that's accomplished using a class instance variable. Although in this case it would probably be better to remove the caching variable. I don't think these methods are called more than once during a request, and even if they did it's highly unlikely the would become a bottleneck.
This commit is contained in:
@@ -376,6 +376,9 @@ Style/BlockDelimiters:
|
||||
Style/ClassCheck:
|
||||
Enabled: true
|
||||
|
||||
Style/ClassVars:
|
||||
Enabled: true
|
||||
|
||||
Style/Not:
|
||||
Enabled: true
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@ module Measurable
|
||||
|
||||
class_methods do
|
||||
def title_max_length
|
||||
@@title_max_length ||= (columns.find { |c| c.name == "title" }.limit rescue nil) || 80
|
||||
@title_max_length ||= (columns.find { |c| c.name == "title" }.limit rescue nil) || 80
|
||||
end
|
||||
|
||||
def responsible_name_max_length
|
||||
@@responsible_name_max_length ||= (columns.find { |c| c.name == "responsible_name" }.limit rescue nil) || 60
|
||||
@responsible_name_max_length ||= (columns.find { |c| c.name == "responsible_name" }.limit rescue nil) || 60
|
||||
end
|
||||
|
||||
def question_max_length
|
||||
|
||||
@@ -42,11 +42,11 @@ class Organization < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.name_max_length
|
||||
@@name_max_length ||= columns.find { |c| c.name == "name" }.limit || 60
|
||||
@name_max_length ||= columns.find { |c| c.name == "name" }.limit || 60
|
||||
end
|
||||
|
||||
def self.responsible_name_max_length
|
||||
@@responsible_name_max_length ||= columns.find { |c| c.name == "responsible_name" }.limit || 60
|
||||
@responsible_name_max_length ||= columns.find { |c| c.name == "responsible_name" }.limit || 60
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -313,7 +313,7 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def self.username_max_length
|
||||
@@username_max_length ||= columns.find { |c| c.name == "username" }.limit || 60
|
||||
@username_max_length ||= columns.find { |c| c.name == "username" }.limit || 60
|
||||
end
|
||||
|
||||
def self.minimum_required_age
|
||||
|
||||
Reference in New Issue
Block a user