Class: Axeman::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/axeman/subscriber.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSubscriber

Returns a new instance of Subscriber.



5
6
# File 'lib/axeman/subscriber.rb', line 5

def initialize
end

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



3
4
5
# File 'lib/axeman/subscriber.rb', line 3

def actions
  @actions
end

Instance Method Details

#notice(controller, action) ⇒ Object



8
9
10
11
12
13
# File 'lib/axeman/subscriber.rb', line 8

def notice(controller, action)
  self.actions ||= {}
  self.actions[controller] ||= Hash.new
  self.actions[controller][action] ||= 0
  self.actions[controller][action] += 1      
end

#subscribe!Object



15
16
17
18
19
20
# File 'lib/axeman/subscriber.rb', line 15

def subscribe!
  ActiveSupport::Notifications.subscribe("process_action.action_controller") do |*args|
    event = ActiveSupport::Notifications::Event.new(*args)
    notice(event.payload[:controller], event.payload[:action])
  end
end

#totalObject



22
23
24
# File 'lib/axeman/subscriber.rb', line 22

def total
  actions
end