Class: CommandTower::Audit::Persistence::Subscriber
- Inherits:
-
Object
- Object
- CommandTower::Audit::Persistence::Subscriber
- Defined in:
- lib/command_tower/audit/persistence/subscriber.rb
Constant Summary collapse
- PATTERN =
/\Acommand_tower\.audit(?:\.|\z)/
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.attach! ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/command_tower/audit/persistence/subscriber.rb', line 10 def attach! detach! subscriber = new @subscriptions = [ ActiveSupport::Notifications.subscribe(PATTERN) do |name, started, finished, id, payload| event = ActiveSupport::Notifications::Event.new(name, started, finished, id, payload) subscriber.call(event) end ] end |
.detach! ⇒ Object
21 22 23 24 |
# File 'lib/command_tower/audit/persistence/subscriber.rb', line 21 def detach! Array(@subscriptions).each { |subscription| ActiveSupport::Notifications.unsubscribe(subscription) } @subscriptions = [] end |
.subscriptions ⇒ Object
26 27 28 |
# File 'lib/command_tower/audit/persistence/subscriber.rb', line 26 def subscriptions Array(@subscriptions) end |
Instance Method Details
#call(event) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/command_tower/audit/persistence/subscriber.rb', line 31 def call(event) payload = event.payload.to_h.with_indifferent_access return unless persistable?(payload) persist!(payload) end |