Sha256: 83441f7205386f0acaf575a0965d5a43824abc21dc74912be253a1d16cad8b05

Contents?: true

Size: 949 Bytes

Versions: 2

Compression:

Stored size: 949 Bytes

Contents

require 'easy_diff'

require 'mongoid/history/version'
require 'mongoid/history/mongoid'
require 'mongoid/history/tracker'
require 'mongoid/history/trackable'

module Mongoid
  module History
    GLOBAL_TRACK_HISTORY_FLAG = 'mongoid_history_trackable_enabled'

    mattr_accessor :tracker_class_name
    mattr_accessor :trackable_class_options
    mattr_accessor :modifier_class_name
    mattr_accessor :current_user_method

    def self.tracker_class
      @tracker_class ||= tracker_class_name.to_s.classify.constantize
    end

    def self.disable(&_block)
      Thread.current[GLOBAL_TRACK_HISTORY_FLAG] = false
      yield
    ensure
      Thread.current[GLOBAL_TRACK_HISTORY_FLAG] = true
    end

    def self.enabled?
      Thread.current[GLOBAL_TRACK_HISTORY_FLAG] != false
    end
  end
end

Mongoid::History.modifier_class_name = 'User'
Mongoid::History.trackable_class_options = {}
Mongoid::History.current_user_method ||= :current_user

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongoid-history-0.4.7 lib/mongoid/history.rb
mongoid-history-0.4.5 lib/mongoid/history.rb