Class: ActiveRecord::Scoping::ScopeRegistry
- 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 collapse
Instance Method Summary collapse
- #current_scope(model, skip_inherited_scope = false) ⇒ Object
- #global_current_scope(model, skip_inherited_scope = false) ⇒ Object
- #ignore_default_scope(model, skip_inherited_scope = false) ⇒ Object
-
#initialize ⇒ ScopeRegistry
constructor
A new instance of ScopeRegistry.
- #set_current_scope(model, value) ⇒ Object
- #set_global_current_scope(model, value) ⇒ Object
- #set_ignore_default_scope(model, value) ⇒ Object
Constructor Details
#initialize ⇒ ScopeRegistry
Returns a new instance of ScopeRegistry.
85 86 87 88 89 |
# File 'activerecord/lib/active_record/scoping.rb', line 85 def initialize @current_scope = {} @ignore_default_scope = {} @global_current_scope = {} end |
Class Method Details
.instance ⇒ Object
80 81 82 |
# File 'activerecord/lib/active_record/scoping.rb', line 80 def instance ActiveSupport::IsolatedExecutionState[:active_record_scope_registry] ||= new end |
Instance Method Details
#current_scope(model, skip_inherited_scope = false) ⇒ Object
91 92 93 |
# File 'activerecord/lib/active_record/scoping.rb', line 91 def current_scope(model, skip_inherited_scope = false) value_for(@current_scope, model, skip_inherited_scope) end |
#global_current_scope(model, skip_inherited_scope = false) ⇒ Object
107 108 109 |
# File 'activerecord/lib/active_record/scoping.rb', line 107 def global_current_scope(model, skip_inherited_scope = false) value_for(@global_current_scope, model, skip_inherited_scope) end |
#ignore_default_scope(model, skip_inherited_scope = false) ⇒ Object
99 100 101 |
# File 'activerecord/lib/active_record/scoping.rb', line 99 def ignore_default_scope(model, skip_inherited_scope = false) value_for(@ignore_default_scope, model, skip_inherited_scope) end |
#set_current_scope(model, value) ⇒ Object
95 96 97 |
# File 'activerecord/lib/active_record/scoping.rb', line 95 def set_current_scope(model, value) set_value_for(@current_scope, model, value) end |
#set_global_current_scope(model, value) ⇒ Object
111 112 113 |
# File 'activerecord/lib/active_record/scoping.rb', line 111 def set_global_current_scope(model, value) set_value_for(@global_current_scope, model, value) end |
#set_ignore_default_scope(model, value) ⇒ Object
103 104 105 |
# File 'activerecord/lib/active_record/scoping.rb', line 103 def set_ignore_default_scope(model, value) set_value_for(@ignore_default_scope, model, value) end |