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


30
31
32
# File 'lib/activerecord/delay_touching.rb', line 30

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

#delay_touching?Boolean

Are we currently executing in a delay_touching block?

Returns:

  • (Boolean)


35
36
37
# File 'lib/activerecord/delay_touching.rb', line 35

def delay_touching?
  DelayTouching.state.nesting > 0
end