Module: GraphMediator
- Defined in:
- lib/graph_mediator.rb,
lib/graph_mediator/locking.rb,
lib/graph_mediator/version.rb,
lib/graph_mediator/mediator.rb
Overview
GraphMediator
GraphMediator is used to coordinate changes between a graph of ActiveRecord objects related to a root node. See README.rdoc for details.
GraphMediator::Base::DSL - is the simple class macro language used to set up mediation.
Versioning and Optimistic Locking
If you include an integer lock_version column in your class, it will be incremented only once within a mediated_transaction and will serve as the optimistic locking check for the entire graph so long as you have declared all your dependent models for mediation.
Outside of a mediated_transaction, lock_version will increment per update as usual.
Convenience Methods for Save Without Mediation
There are convenience method to perform a save, save!, toggle, toggle!, update_attribute, update_attributes or update_attributes! call without mediation. They are of the form <method>_without_mediation<punc>
For example, save_without_mediation! is equivalent to:
instance.disable_mediation!
instance.save!
instance.enable_mediation!
Overriding
GraphMediator overrides ActiveRecord’s save_without_transaction to slip in mediation just before the save process is wrapped in a transaction.
-
save_without_transaction
-
save_without_transaction_with_mediation
-
save_without_transaction_without_mediation
may all be overridden in your implementation class, but they end up being defined locally by GraphMediator, so you can override with something like alias_method_chain, but will need to be in a subclass to use super.
My original intention was to define aliased overrides in MediatorProxy if the target was a method in a superclass (like save), so that the implementation class could make a simple def foo; something; super; end override, but this is prevented by a bug in ruby 1.8 with aliasing of methods that use super in a module. redmine.ruby-lang.org/issues/show/734
Defined Under Namespace
Modules: AliasExtension, Configuration, DSL, Locking, Proxy, Util Classes: Mediator, MediatorException
Constant Summary collapse
- CALLBACKS =
[:before_mediation, :mediate_reconciles, :mediate_caches, :mediate_bumps]
- SAVE_METHODS =
[:save_without_transactions, :save_without_transactions!]
- VERSION =
"0.2.3"
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
67 68 69 70 71 72 |
# File 'lib/graph_mediator.rb', line 67 def included(base) base.class_eval do extend DSL end initialize_for_mediation(base) end |