Module: Mongoid::Touchable

Extended by:
Touchable
Included in:
Touchable
Defined in:
lib/mongoid/touchable.rb

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

Instance Method Details

#define_touchable!(association) ⇒ Class

Add the association to the touchable associations if the touch option was provided.

Examples:

Add the touchable.

Model.define_touchable!(assoc)

Parameters:

Returns:

  • (Class)

    The model class.



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.embedded?
  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.

Returns:

  • (true | false)

    Whether touch callbacks are suppressed.



183
184
185
# File 'lib/mongoid/touchable.rb', line 183

def touch_callbacks_suppressed?(name)
  touch_callback_statuses[name]
end