Class: ActiveRecord::Scoping::ScopeRegistry
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | activerecord/lib/active_record/scoping.rb |
Overview
This class stores the :current_scope
and :ignore_default_scope
values for different classes. The registry is stored as either a thread or fiber local depending on the application configuration.
This class allows you to store and get the scope values on different classes and different types of scopes. For example, if you are attempting to get the current_scope for the Board
model, then you would use the following code:
registry = ActiveRecord::Scoping::ScopeRegistry
registry.set_current_scope(Board, some_new_scope)
Now when you run:
registry.current_scope(Board)
You will obtain whatever was defined in some_new_scope
.
Class Method Summary
- .instance
- .new ⇒ ScopeRegistry constructor
Instance Attribute Summary
- #current_scope(model, skip_inherited_scope = false) readonly
- #global_current_scope(model, skip_inherited_scope = false) readonly
- #ignore_default_scope(model, skip_inherited_scope = false) readonly
- #set_current_scope(model, value) readonly
- #set_global_current_scope(model, value) readonly
- #set_ignore_default_scope(model, value) readonly
Instance Method Summary
-
#set_value_for(scope_type, model, value)
private
Sets the
value
for a givenscope_type
andmodel
. -
#value_for(scope_type, model, skip_inherited_scope = false)
private
Obtains the value for a given
scope_type
andmodel
.
Constructor Details
.new ⇒ ScopeRegistry
# File 'activerecord/lib/active_record/scoping.rb', line 85
def initialize @current_scope = {} @ignore_default_scope = {} @global_current_scope = {} end
Class Method Details
.instance
[ GitHub ]# File 'activerecord/lib/active_record/scoping.rb', line 80
def instance ActiveSupport::IsolatedExecutionState[:active_record_scope_registry] ||= new end
Instance Attribute Details
#current_scope(model, skip_inherited_scope = false) (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/scoping.rb', line 91
delegate :current_scope, :set_current_scope, :ignore_default_scope, :set_ignore_default_scope, :global_current_scope, :set_global_current_scope, to: :instance
#global_current_scope(model, skip_inherited_scope = false) (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/scoping.rb', line 107
delegate :current_scope, :set_current_scope, :ignore_default_scope, :set_ignore_default_scope, :global_current_scope, :set_global_current_scope, to: :instance
#ignore_default_scope(model, skip_inherited_scope = false) (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/scoping.rb', line 99
delegate :current_scope, :set_current_scope, :ignore_default_scope, :set_ignore_default_scope, :global_current_scope, :set_global_current_scope, to: :instance
#set_current_scope(model, value) (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/scoping.rb', line 95
delegate :current_scope, :set_current_scope, :ignore_default_scope, :set_ignore_default_scope, :global_current_scope, :set_global_current_scope, to: :instance
#set_global_current_scope(model, value) (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/scoping.rb', line 111
delegate :current_scope, :set_current_scope, :ignore_default_scope, :set_ignore_default_scope, :global_current_scope, :set_global_current_scope, to: :instance
#set_ignore_default_scope(model, value) (readonly)
[ GitHub ]# File 'activerecord/lib/active_record/scoping.rb', line 103
delegate :current_scope, :set_current_scope, :ignore_default_scope, :set_ignore_default_scope, :global_current_scope, :set_global_current_scope, to: :instance
Instance Method Details
#set_value_for(scope_type, model, value) (private)
Sets the value
for a given scope_type
and model
.
# File 'activerecord/lib/active_record/scoping.rb', line 130
def set_value_for(scope_type, model, value) scope_type[model.name] = value end
#value_for(scope_type, model, skip_inherited_scope = false) (private)
Obtains the value for a given scope_type
and model
.
# File 'activerecord/lib/active_record/scoping.rb', line 117
def value_for(scope_type, model, skip_inherited_scope = false) return scope_type[model.name] if skip_inherited_scope klass = model base = model.base_class while klass != base value = scope_type[klass.name] return value if value klass = klass.superclass end scope_type[klass.name] end