module Mongoid::History

Constants

GLOBAL_TRACK_HISTORY_FLAG
VERSION

Attributes

current_user_method[RW]
modifier_class_name[RW]
trackable_settings[RW]
tracker_class_name[RW]

Public Class Methods

default_settings() click to toggle source
# File lib/mongoid/history.rb, line 49
def default_settings
  @default_settings ||= { paranoia_field: 'deleted_at' }
end
disable() { || ... } click to toggle source
# File lib/mongoid/history.rb, line 22
def disable
  original_flag = store[GLOBAL_TRACK_HISTORY_FLAG]
  store[GLOBAL_TRACK_HISTORY_FLAG] = false
  yield if block_given?
ensure
  store[GLOBAL_TRACK_HISTORY_FLAG] = original_flag if block_given?
end
Also aliased as: disable!
disable!()
Alias for: disable
enable() { || ... } click to toggle source
# File lib/mongoid/history.rb, line 30
def enable
  original_flag = store[GLOBAL_TRACK_HISTORY_FLAG]
  store[GLOBAL_TRACK_HISTORY_FLAG] = true
  yield if block_given?
ensure
  store[GLOBAL_TRACK_HISTORY_FLAG] = original_flag if block_given?
end
Also aliased as: enable!
enable!()
Alias for: enable
enabled?() click to toggle source
# File lib/mongoid/history.rb, line 41
def enabled?
  store[GLOBAL_TRACK_HISTORY_FLAG] != false
end
reset!() click to toggle source
# File lib/mongoid/history.rb, line 57
def reset!
  Mongoid::History.modifier_class_name = 'User'
  Mongoid::History.trackable_settings = {}
  Mongoid::History.current_user_method ||= :current_user

  Mongoid.models.each do |model|
    next unless model.included_modules.include? Mongoid::History::Trackable

    model.singleton_class.class_eval do
      # Inverse of class_attribute
      %i[mongoid_history_options
         mongoid_history_options=
         mongoid_history_options?].each { |m| remove_possible_method(m) }
    end
  end
end
store() click to toggle source
# File lib/mongoid/history.rb, line 45
def store
  defined?(RequestStore) ? RequestStore.store : Thread.current
end
trackable_class_settings(trackable_class) click to toggle source
# File lib/mongoid/history.rb, line 53
def trackable_class_settings(trackable_class)
  trackable_settings[trackable_class.name.to_sym] || default_settings
end