Module: ActsAsRankedList::ActiveRecord::SkipPersistence::ClassMethods

Defined in:
lib/acts_as_ranked_list/active_record/skip_persistence.rb

Class Method Summary collapse

Class Method Details

.with_skip_persistence(klasses = []) { ... } ⇒ void

This method returns an undefined value.

Pass a block to this method to prevent persisting ::ActiveRecord updates and callbacks. You may pass an array of classes to prevent persisting. These ::ActiveRecord models must include the acts_as_ranked_list concern.

Examples:

with an ::ActiveRecord model of the name TodoItem:

TodoItem.with_skip_persistence { TodoItem.find(4).increase_rank }

Parameters:

  • klasses (Array<Class>) (defaults to: [])

    array of klasses to prevent persisting

Yields:

  • the block to execute with changes to the instances

Raises:

  • (ArgumentError)

    raised if optional klasses argument is not an array of ::ActiveRecord objects

Since:

  • 0.2.0



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/acts_as_ranked_list/active_record/skip_persistence.rb', line 25

def with_skip_persistence(klasses = [], &blk)
  raise ::ArgumentError unless klasses.is_a?(Array)

  klasses << self

  raise ::ArgumentError unless active_record_objects?(klasses)

  SkipPersistence.with_applied_klasses(klasses) do
    yield
  end
end