Module: ActiveRecord::DelayTouching::ClassMethods

Defined in:
lib/activerecord/delay_touching.rb

Overview

These get added as class methods to ActiveRecord::Base.

Instance Method Summary collapse

Instance Method Details

#delay_touching(&block) ⇒ Object

Lets you batch up your touch calls for the duration of a block.

Examples

# Touches Person.first once, not twice, when the block exits.
ActiveRecord::Base.delay_touching do
  Person.first.touch
  Person.first.touch
end


32
33
34
# File 'lib/activerecord/delay_touching.rb', line 32

def delay_touching(&block)
  DelayTouching.call &block
end

#delay_touching?Boolean

Are we currently executing in a delay_touching block?

Returns:

  • (Boolean)


37
38
39
# File 'lib/activerecord/delay_touching.rb', line 37

def delay_touching?
  DelayTouching.state.nesting > 0
end