Sha256: f6271133eaf0de07582cb84807ba0ca7b803d5ea4ff839f90a287cedc0c93558

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 KB

Contents

module Mongoid::History
  class Sweeper < Mongoid::Observer
    def controller
      Thread.current[:mongoid_history_sweeper_controller]
    end

    def controller=(value)
      Thread.current[:mongoid_history_sweeper_controller] = value
    end

    def self.observed_classes
      [Mongoid::History.tracker_class]
    end

    # Hook to ActionController::Base#around_filter.
    # Runs before a controller action is run.
    # It should always return true so controller actions
    # can continue.
    def before(controller)
      self.controller = controller
      true
    end

    # Hook to ActionController::Base#around_filter.
    # Runs after a controller action is run.
    # Clean up so that the controller can
    # be collected after this request
    def after(controller)
      self.controller = nil
    end

    def before_create(track)
      modifier_field = track.trackable.history_trackable_options[:modifier_field]
      modifier = track.trackable.send modifier_field
      track.modifier = current_user unless modifier
    end

    def current_user
      if controller.respond_to?(Mongoid::History.current_user_method, true)
        controller.send Mongoid::History.current_user_method
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 3 rubygems

Version Path
mongoid-history-0.4.0 lib/mongoid/history/sweeper.rb
mongoid-history-0.3.3 lib/mongoid/history/sweeper.rb
mongoid-history-0.3.2 lib/mongoid/history/sweeper.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/mongoid-history-0.3.1/lib/mongoid/history/sweeper.rb
mongoid-history-0.3.1 lib/mongoid/history/sweeper.rb
mongoid-history-patched-0.2.3 lib/mongoid/history/sweeper.rb
mongoid-history-0.3.0 lib/mongoid/history/sweeper.rb
mongoid-history-0.2.4 lib/mongoid/history/sweeper.rb