Module: Mongoid::Touchable
Overview
Mixin module which is included in Mongoid::Document to add “touch” functionality to update a document’s timestamp(s) atomically.
Defined Under Namespace
Modules: InstanceMethods
Instance Method Summary collapse
-
#define_touchable!(association) ⇒ Class
Add the association to the touchable associations if the touch option was provided.
-
#suppress_touch_callbacks(name) ⇒ Object
private
Suppresses touch callbacks for the named class, for the duration of the associated block.
-
#touch_callbacks_suppressed?(name) ⇒ true | false
private
Queries whether touch callbacks are being suppressed for the named class.
Instance Method Details
#define_touchable!(association) ⇒ Class
Add the association to the touchable associations if the touch option was provided.
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/mongoid/touchable.rb', line 153 def define_touchable!(association) name = association.name method_name = define_relation_touch_method(name, association) association.inverse_class.tap do |klass| klass.after_save method_name klass.after_destroy method_name # Embedded docs handle touch updates recursively within # the #touch method itself klass.after_touch method_name unless association. end end |
#suppress_touch_callbacks(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Suppresses touch callbacks for the named class, for the duration of the associated block.
170 171 172 173 174 175 |
# File 'lib/mongoid/touchable.rb', line 170 def suppress_touch_callbacks(name) save, touch_callback_statuses[name] = touch_callback_statuses[name], true yield ensure touch_callback_statuses[name] = save end |
#touch_callbacks_suppressed?(name) ⇒ true | false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Queries whether touch callbacks are being suppressed for the named class.
183 184 185 |
# File 'lib/mongoid/touchable.rb', line 183 def touch_callbacks_suppressed?(name) touch_callback_statuses[name] end |