Module: GraphMediator::Proxy
- Extended by:
- Util
- Defined in:
- lib/graph_mediator.rb
Overview
All of the working methods for mediation, plus initial call backs.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#being_destroyed? ⇒ Boolean
True if this instance is currently in the middle of being destroyed.
-
#current_mediation_phase ⇒ Object
Returns the state of the current_mediator or nil.
-
#currently_mediating? ⇒ Boolean
True if there is currently a mediated transaction begun for this instance.
-
#destroy_with_flag ⇒ Object
Surrounding the base destroy ensures that instance is marked in Thread before any other callbacks occur (notably the collection destroy dependents pushed into the before_destroy callback).
-
#disable_mediation! ⇒ Object
Turn off mediation for this instance.
-
#enable_mediation! ⇒ Object
Turn on mediation for this instance (on by default).
-
#mediated_changes ⇒ Object
Returns the hash of changes to the graph being tracked by the current mediator or nil if not currently mediating.
-
#mediated_transaction(&block) ⇒ Object
Wraps the given block in a transaction and begins mediation.
-
#mediation_enabled? ⇒ Boolean
By default, every instance will be mediated and this will return true.
Methods included from Util
Instance Method Details
#being_destroyed? ⇒ Boolean
True if this instance is currently in the middle of being destroyed. Set by code slipped around the core ActiveRecord::Base#destroy via destroy_with_flag.
Used by dependents in the mediation process to check whether they should update their root (see notes under the mediate
method).
282 283 284 |
# File 'lib/graph_mediator.rb', line 282 def being_destroyed? instances_being_destroyed.include?(id) end |
#current_mediation_phase ⇒ Object
Returns the state of the current_mediator or nil.
255 256 257 |
# File 'lib/graph_mediator.rb', line 255 def current_mediation_phase current_mediator.try(:aasm_current_state) end |
#currently_mediating? ⇒ Boolean
True if there is currently a mediated transaction begun for this instance.
250 251 252 |
# File 'lib/graph_mediator.rb', line 250 def currently_mediating? !current_mediator.nil? end |
#destroy_with_flag ⇒ Object
Surrounding the base destroy ensures that instance is marked in Thread before any other callbacks occur (notably the collection destroy dependents pushed into the before_destroy callback).
If we instead relied on on the before_destroy, after_destroy callbacks, we would be at the mercy of declaration order in the class for the GraphMediator include versus the association macro.
293 294 295 296 297 298 |
# File 'lib/graph_mediator.rb', line 293 def destroy_with_flag _mark_being_destroyed destroy_without_flag ensure _unmark_being_destroyed end |
#disable_mediation! ⇒ Object
Turn off mediation for this instance. If currently mediating, it will finish normally, but new mediators will start disabled.
267 268 269 |
# File 'lib/graph_mediator.rb', line 267 def disable_mediation! @graph_mediator_mediation_disabled = true end |
#enable_mediation! ⇒ Object
Turn on mediation for this instance (on by default).
272 273 274 |
# File 'lib/graph_mediator.rb', line 272 def enable_mediation! @graph_mediator_mediation_disabled = false end |
#mediated_changes ⇒ Object
Returns the hash of changes to the graph being tracked by the current mediator or nil if not currently mediating.
261 262 263 |
# File 'lib/graph_mediator.rb', line 261 def mediated_changes current_mediator.try(:changes) end |
#mediated_transaction(&block) ⇒ Object
Wraps the given block in a transaction and begins mediation.
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/graph_mediator.rb', line 232 def mediated_transaction(&block) m_debug("#{self}.mediated_transaction called") mediator = _get_mediator result = nil transaction do result = mediator.mediate(&block) end m_debug("#{self}.mediated_transaction completed successfully") return result ensure if mediator && mediator.idle? mediators.delete(self.id) mediators_for_new_records.delete(mediator) end end |
#mediation_enabled? ⇒ Boolean
By default, every instance will be mediated and this will return true. You can turn mediation on or off on an instance by instance basis with calls to disable_mediation! or enable_mediation!.
Mediation may also be disabled at the class level, but enabling or disabling an instance supercedes this.
318 319 320 321 322 |
# File 'lib/graph_mediator.rb', line 318 def mediation_enabled? enabled = @graph_mediator_mediation_disabled.nil? ? self.class.mediation_enabled? : !@graph_mediator_mediation_disabled end |