Class: Simple::Sharding::ShardThreadRegistry
- Inherits:
-
Object
- Object
- Simple::Sharding::ShardThreadRegistry
- Extended by:
- ActiveSupport::PerThreadRegistry
- Defined in:
- lib/simple/sharding/shard_thread_registry.rb
Instance Attribute Summary collapse
-
#_current_shard_id ⇒ Object
Returns the value of attribute _current_shard_id.
Class Method Summary collapse
- .connect_to_master? ⇒ Boolean
-
.current_shard_id ⇒ Object
Returns the current shard id (for the current Thread).
- .current_shard_id=(shard_id) ⇒ Object
-
.notify_connection_retrieved ⇒ Object
notifies the current connection was used (wee keep track of this to warn the user in case the connection is not used).
-
.pop_current_shard ⇒ Object
removes shard connection to the stack.
-
.push_current_shard(shard_id) ⇒ Object
adds shard connection to the stack.
- .shard_connection_used_stack ⇒ Object
- .shard_id_stack ⇒ Object
Instance Attribute Details
#_current_shard_id ⇒ Object
Returns the value of attribute _current_shard_id.
6 7 8 |
# File 'lib/simple/sharding/shard_thread_registry.rb', line 6 def _current_shard_id @_current_shard_id end |
Class Method Details
.connect_to_master? ⇒ Boolean
27 28 29 |
# File 'lib/simple/sharding/shard_thread_registry.rb', line 27 def self.connect_to_master? _current_shard_id.nil? end |
.current_shard_id ⇒ Object
Returns the current shard id (for the current Thread)
22 23 24 |
# File 'lib/simple/sharding/shard_thread_registry.rb', line 22 def self.current_shard_id shard_id_stack.last end |
.current_shard_id=(shard_id) ⇒ Object
35 36 37 |
# File 'lib/simple/sharding/shard_thread_registry.rb', line 35 def self.current_shard_id=(shard_id) self._current_shard_id = shard_id.blank? ? nil : shard_id.to_sym end |
.notify_connection_retrieved ⇒ Object
notifies the current connection was used (wee keep track of this to warn the user in case the connection is not used)
52 53 54 |
# File 'lib/simple/sharding/shard_thread_registry.rb', line 52 def self.notify_connection_retrieved shard_connection_used_stack[-1] = true if shard_connection_used_stack.present? end |
.pop_current_shard ⇒ Object
removes shard connection to the stack
57 58 59 |
# File 'lib/simple/sharding/shard_thread_registry.rb', line 57 def self.pop_current_shard [shard_id_stack.pop, shard_connection_used_stack.pop] end |
.push_current_shard(shard_id) ⇒ Object
adds shard connection to the stack
40 41 42 43 44 45 46 47 |
# File 'lib/simple/sharding/shard_thread_registry.rb', line 40 def self.push_current_shard(shard_id) # this line supresses the unused connection warning when there are nested # using_shard blocks. We suppress the warning because we view nested using_shard # blocks as a override notify_connection_retrieved shard_id_stack.push(shard_id.blank? ? nil : shard_id.to_sym) shard_connection_used_stack.push(false) end |
.shard_connection_used_stack ⇒ Object
18 |
# File 'lib/simple/sharding/shard_thread_registry.rb', line 18 def self.shard_connection_used_stack; self._shard_connection_used_stack ||= [] end |
.shard_id_stack ⇒ Object
17 |
# File 'lib/simple/sharding/shard_thread_registry.rb', line 17 def self.shard_id_stack; self._shard_id_stack ||= [] end |