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.
22 lines
462 B
Ruby
22 lines
462 B
Ruby
module Measurable
|
|
extend ActiveSupport::Concern
|
|
|
|
class_methods do
|
|
def title_max_length
|
|
@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
|
|
end
|
|
|
|
def question_max_length
|
|
140
|
|
end
|
|
|
|
def description_max_length
|
|
6000
|
|
end
|
|
end
|
|
end
|