Module: Narrator::ControllerAdditions

Defined in:
lib/narrator/controller_additions.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



22
23
24
25
# File 'lib/narrator/controller_additions.rb', line 22

def self.included(base)
  base.extend ClassMethods
  base.helper_method :narrate
end

Instance Method Details

#narrate(subject, actor = current_user, target = nil, verb = params[:action], context = nil) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/narrator/controller_additions.rb', line 27

def narrate(
  subject,
  actor = current_user,
  target = nil,
  verb = params[:action],
  context = nil
)
  if subject.class.respond_to? :track_user_activity
    # Add some config way of determining to use delayed jobs.
    subject.class.track_user_activity(
      (subject.blank? ? nil : subject.id),
      subject.class.to_s,
      (actor.blank? ? nil : actor.id),
      actor.class.to_s,
      (target.blank? ? nil : target.id),
      target.class.to_s,
      verb,
      context
    )
  end
end