Module: Mongoid::Touchable

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

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.



145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/mongoid/touchable.rb', line 145

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.



162
163
164
165
166
167
# File 'lib/mongoid/touchable.rb', line 162

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.



175
176
177
# File 'lib/mongoid/touchable.rb', line 175

def touch_callbacks_suppressed?(name)
  touch_callback_statuses[name]
end