class ActiveRecord::Scoping::ScopeRegistry
:nodoc:
“Board”, some_new_scope)
ActiveRecord::Scoping::ScopeRegistry.set_value_for(:current_scope,
object, so the above example code can also be called as:
and set_value_for
methods are delegated to the current ScopeRegistry
You will obtain whatever was defined in some_new_scope
. The value_for
registry.value_for(:current_scope, “Board”)
Now when you run:
registry.set_value_for(:current_scope, “Board”, some_new_scope)
registry = ActiveRecord::Scoping::ScopeRegistry
following code:
to get the current_scope for the Board
model, then you would use the
classes and different types of scopes. For example, if you are attempting
This class allows you to store and get the scope values on different
accessed through ScopeRegistry.current
.
for different classes. The registry is stored as a thread local, which is
This class stores the :current_scope
and :ignore_default_scope
values
def initialize
def initialize @registry = Hash.new { |hash, key| hash[key] = {} } end
def raise_invalid_scope_type!(scope_type)
def raise_invalid_scope_type!(scope_type) if !VALID_SCOPE_TYPES.include?(scope_type) raise ArgumentError, "Invalid scope type '#{scope_type}' sent to the registry. Scope types must be included in VALID_SCOPE_TYPES" end end
def set_value_for(scope_type, variable_name, value)
def set_value_for(scope_type, variable_name, value) raise_invalid_scope_type!(scope_type) @registry[scope_type][variable_name] = value end
def value_for(scope_type, variable_name)
def value_for(scope_type, variable_name) raise_invalid_scope_type!(scope_type) @registry[scope_type][variable_name] end