Class: ActiveShard::ScopeManager

Inherits:
Object
  • Object
show all
Defined in:
lib/active_shard/scope_manager.rb

Overview

ScopeManager handles the passing of messages to a Scope based on the current thread.

Allows consumers to operate on a Scope duck-typed object without handling the Thread local variable stuff.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ScopeManager

Initializes a scope manager

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :scope_class (Class, #new)

    class to use when instantiating scope instances



19
20
21
# File 'lib/active_shard/scope_manager.rb', line 19

def initialize( options={} )
  self.scope_class = options[:scope_class] if options[:scope_class]
end

Instance Method Details

#active_shard_for_schema(*args) ⇒ Object



37
38
39
# File 'lib/active_shard/scope_manager.rb', line 37

def active_shard_for_schema( *args )
  scope.active_shard_for_schema( *args )
end

#pop(*args) ⇒ Object



31
32
33
# File 'lib/active_shard/scope_manager.rb', line 31

def pop( *args )
  scope.pop( *args )
end

#push(*args) ⇒ Object



25
26
27
# File 'lib/active_shard/scope_manager.rb', line 25

def push( *args )
  scope.push( *args )
end

#scope_classObject

Returns the current scope_class



56
57
58
# File 'lib/active_shard/scope_manager.rb', line 56

def scope_class
  @scope_class ||= Scope
end

#scope_class=(klass) ⇒ Object

Sets the class to use for maintaining Thread-local scopes

Instances of klass must respond to:

#push
#pop
#active_shard_for_schema

Parameters:

  • klass (Class, #new)

    scope_class



50
51
52
# File 'lib/active_shard/scope_manager.rb', line 50

def scope_class=( klass )
  @scope_class = klass
end