Class: ActiveRecord::Scoping::ScopeRegistry

Inherits:
Object
  • Object
show all
Defined in:
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

Constructor Details

#initializeScopeRegistry

Returns a new instance of ScopeRegistry.

[View source]

86
87
88
89
90
# File 'lib/active_record/scoping.rb', line 86

def initialize
  @current_scope        = {}
  @ignore_default_scope = {}
  @global_current_scope = {}
end

Class Method Details

.instanceObject

[View source]

81
82
83
# File 'lib/active_record/scoping.rb', line 81

def instance
  ActiveSupport::IsolatedExecutionState[:active_record_scope_registry] ||= new
end

Instance Method Details

#current_scope(model, skip_inherited_scope = false) ⇒ Object

[View source]

92
93
94
# File 'lib/active_record/scoping.rb', line 92

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

[View source]

108
109
110
# File 'lib/active_record/scoping.rb', line 108

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

[View source]

100
101
102
# File 'lib/active_record/scoping.rb', line 100

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

[View source]

96
97
98
# File 'lib/active_record/scoping.rb', line 96

def set_current_scope(model, value)
  set_value_for(@current_scope, model, value)
end

#set_global_current_scope(model, value) ⇒ Object

[View source]

112
113
114
# File 'lib/active_record/scoping.rb', line 112

def set_global_current_scope(model, value)
  set_value_for(@global_current_scope, model, value)
end

#set_ignore_default_scope(model, value) ⇒ Object

[View source]

104
105
106
# File 'lib/active_record/scoping.rb', line 104

def set_ignore_default_scope(model, value)
  set_value_for(@ignore_default_scope, model, value)
end