Class: RaceGuard::Context::Snapshot
- Inherits:
-
Object
- Object
- RaceGuard::Context::Snapshot
- Defined in:
- lib/race_guard/context.rb
Overview
Immutable snapshot of #current state for the calling thread. protected_blocks is ordered outermost-first (first push_protected is index 0; innermost / most recent is last). Reserved for RaceGuard.protect (Task 2.1).
Instance Attribute Summary collapse
-
#current_rule ⇒ Object
readonly
Returns the value of attribute current_rule.
-
#in_transaction ⇒ Object
(also: #in_transaction?)
readonly
Returns the value of attribute in_transaction.
-
#protected_blocks ⇒ Object
readonly
Returns the value of attribute protected_blocks.
-
#thread_id ⇒ Object
readonly
Returns the value of attribute thread_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(thread_id:, in_transaction:, protected_blocks:, current_rule:) ⇒ Snapshot
constructor
A new instance of Snapshot.
- #to_h ⇒ Object
Constructor Details
#initialize(thread_id:, in_transaction:, protected_blocks:, current_rule:) ⇒ Snapshot
Returns a new instance of Snapshot.
279 280 281 282 283 284 285 |
# File 'lib/race_guard/context.rb', line 279 def initialize(thread_id:, in_transaction:, protected_blocks:, current_rule:) @thread_id = thread_id @in_transaction = in_transaction @protected_blocks = protected_blocks @current_rule = current_rule freeze end |
Instance Attribute Details
#current_rule ⇒ Object (readonly)
Returns the value of attribute current_rule.
266 267 268 |
# File 'lib/race_guard/context.rb', line 266 def current_rule @current_rule end |
#in_transaction ⇒ Object (readonly) Also known as: in_transaction?
Returns the value of attribute in_transaction.
266 267 268 |
# File 'lib/race_guard/context.rb', line 266 def in_transaction @in_transaction end |
#protected_blocks ⇒ Object (readonly)
Returns the value of attribute protected_blocks.
266 267 268 |
# File 'lib/race_guard/context.rb', line 266 def protected_blocks @protected_blocks end |
#thread_id ⇒ Object (readonly)
Returns the value of attribute thread_id.
266 267 268 |
# File 'lib/race_guard/context.rb', line 266 def thread_id @thread_id end |
Class Method Details
.build(store) ⇒ Object
270 271 272 273 274 275 276 277 |
# File 'lib/race_guard/context.rb', line 270 def self.build(store) new( thread_id: Thread.current.object_id, in_transaction: store.transaction_depth.positive?, protected_blocks: store.protected_blocks.dup.freeze, current_rule: nil ) end |
Instance Method Details
#to_h ⇒ Object
287 288 289 290 291 292 293 294 |
# File 'lib/race_guard/context.rb', line 287 def to_h { 'current_rule' => current_rule, 'in_transaction' => in_transaction, 'protected_blocks' => protected_blocks.map(&:to_s), 'thread_id' => thread_id } end |