Class: AuditLoggable::Sweeper

Inherits:
Object
  • Object
show all
Defined in:
lib/audit_loggable/sweeper.rb

Constant Summary collapse

STORED_DATA =
{
  current_remote_address: :remote_ip,
  current_request_uuid:   :request_uuid,
  current_user:           :current_user
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(current_user_methods: %i[current_user]) ⇒ Sweeper

Returns a new instance of Sweeper.



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

def initialize(current_user_methods: %i[current_user])
  @current_user_methods = ::Array.wrap(current_user_methods).map(&:to_sym)
end

Instance Method Details

#around(controller, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/audit_loggable/sweeper.rb', line 15

def around(controller, &block)
  Store.set({ current_controller: controller }) do
    Store.set(
      STORED_DATA
        .each_pair
        .with_object({}) { |(k, m), h| h[k] = __send__(m) },
      &block
    )
  end
end