Class: RaceGuard::Context::Facade

Inherits:
Object
  • Object
show all
Defined in:
lib/race_guard/context.rb

Overview

Process-singleton facade; all mutations apply only to Thread.current.

Instance Method Summary collapse

Instance Method Details

#begin_transactionObject



67
68
69
70
# File 'lib/race_guard/context.rb', line 67

def begin_transaction
  mutable_store.begin_transaction
  self
end

#currentObject



53
54
55
# File 'lib/race_guard/context.rb', line 53

def current
  Snapshot.build(mutable_store)
end

#defer_after_commit(&block) ⇒ Object



77
78
79
80
# File 'lib/race_guard/context.rb', line 77

def defer_after_commit(&block)
  mutable_store.defer_after_commit(block)
  self
end

#end_transaction(success: true) ⇒ Object



72
73
74
75
# File 'lib/race_guard/context.rb', line 72

def end_transaction(success: true)
  mutable_store.end_transaction(success: success)
  self
end

#pop_protectedObject



62
63
64
65
# File 'lib/race_guard/context.rb', line 62

def pop_protected
  mutable_store.pop_protected
  self
end

#push_protected(name) ⇒ Object



57
58
59
60
# File 'lib/race_guard/context.rb', line 57

def push_protected(name)
  mutable_store.push_protected(name)
  self
end

#reset!Object



82
83
84
85
86
# File 'lib/race_guard/context.rb', line 82

def reset!
  Thread.current[TLS_KEY] = nil
  RMW_THREAD_FLAGS.each { |f| Thread.current[f] = nil }
  self
end

#rmw_pessimistic_lock_active?(model_class, record_id) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/race_guard/context.rb', line 113

def rmw_pessimistic_lock_active?(model_class, record_id)
  mutable_store.rmw_pessimistic_lock_active?(model_class, record_id)
end

#rmw_pessimistic_lock_register!(model_class, record_id) ⇒ Object



108
109
110
111
# File 'lib/race_guard/context.rb', line 108

def rmw_pessimistic_lock_register!(model_class, record_id)
  mutable_store.rmw_pessimistic_lock_register!(model_class, record_id)
  self
end

#rmw_read_age_ms_for(model_class, record_id, attr_name) ⇒ Integer?

Returns age of matching read in milliseconds, or nil if none within TTL.

Returns:

  • (Integer, nil)

    age of matching read in milliseconds, or nil if none within TTL



94
95
96
# File 'lib/race_guard/context.rb', line 94

def rmw_read_age_ms_for(model_class, record_id, attr_name)
  mutable_store.rmw_read_age_ms_for(model_class, record_id, attr_name)
end

#rmw_read_forget!(model_class, record_id, attr_name) ⇒ Object



98
99
100
101
# File 'lib/race_guard/context.rb', line 98

def rmw_read_forget!(model_class, record_id, attr_name)
  mutable_store.rmw_read_forget!(model_class, record_id, attr_name)
  self
end

#rmw_read_forget_record!(model_class, record_id) ⇒ Object



103
104
105
106
# File 'lib/race_guard/context.rb', line 103

def rmw_read_forget_record!(model_class, record_id)
  mutable_store.rmw_read_forget_record!(model_class, record_id)
  self
end

#rmw_read_record!(model_class, record_id, attr_name) ⇒ Object



88
89
90
91
# File 'lib/race_guard/context.rb', line 88

def rmw_read_record!(model_class, record_id, attr_name)
  mutable_store.rmw_read_record!(model_class, record_id, attr_name)
  self
end

#rmw_with_lock_block_depth_for(model_class, record_id) ⇒ Object



117
118
119
# File 'lib/race_guard/context.rb', line 117

def rmw_with_lock_block_depth_for(model_class, record_id)
  RmwWithLockBlockDepth.depth_for(model_class, record_id)
end

#rmw_with_lock_block_enter!(model_class, record_id) ⇒ Object



121
122
123
124
# File 'lib/race_guard/context.rb', line 121

def rmw_with_lock_block_enter!(model_class, record_id)
  RmwWithLockBlockDepth.enter!(model_class, record_id)
  self
end

#rmw_with_lock_block_leave!(model_class, record_id) ⇒ Object



126
127
128
129
# File 'lib/race_guard/context.rb', line 126

def rmw_with_lock_block_leave!(model_class, record_id)
  RmwWithLockBlockDepth.leave!(model_class, record_id)
  self
end