Class: Mongoid::History::Sweeper

Inherits:
Observer
  • Object
show all
Defined in:
lib/mongoid/history/sweeper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.observed_classesObject



11
12
13
# File 'lib/mongoid/history/sweeper.rb', line 11

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

Instance Method Details

#after(controller) ⇒ Object

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



28
29
30
# File 'lib/mongoid/history/sweeper.rb', line 28

def after(controller)
  self.controller = nil
end

#before(controller) ⇒ Object

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



19
20
21
22
# File 'lib/mongoid/history/sweeper.rb', line 19

def before(controller)
  self.controller = controller
  true
end

#before_create(track) ⇒ Object



32
33
34
35
36
# File 'lib/mongoid/history/sweeper.rb', line 32

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

#controllerObject



3
4
5
# File 'lib/mongoid/history/sweeper.rb', line 3

def controller
  Thread.current[:mongoid_history_sweeper_controller]
end

#controller=(value) ⇒ Object



7
8
9
# File 'lib/mongoid/history/sweeper.rb', line 7

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

#current_userObject



38
39
40
41
42
# File 'lib/mongoid/history/sweeper.rb', line 38

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