discourse/lib/multisite_class_var.rb
Robin Ward 3e13becf33 A safe way to create class variables in a multisite environment.
This should allow plugins to set class variables that will not
stomp on other plugins.
2017-09-27 13:00:47 -04:00

21 lines
456 B
Ruby

# Support for a class variable that is multisite aware.
module MultisiteClassVar
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def multisite_class_var(name, &default)
@multisite_class_vars ||= {}
@multisite_class_vars[name] = {}
define_singleton_method(name) do
@multisite_class_vars[name][RailsMultisite::ConnectionManagement.current_db] ||= default.call
end
end
end
end