Sha256: f69dbf082226a4c4ef63b213bbd751884be06812c98edca87802e2cb1a4c5bfe

Contents?: true

Size: 1.47 KB

Versions: 8

Compression:

Stored size: 1.47 KB

Contents

require 'effective_resources'
require 'effective_logging/engine'
require 'effective_logging/version'

module EffectiveLogging
  def self.config_keys
    [
      :logs_table_name, :layout, :additional_statuses,
      :active_storage_enabled, :email_enabled, :sign_in_enabled, :sign_out_enabled
    ]
  end

  include EffectiveGem

  def self.statuses
    @statuses ||= (
      base = [
        'info',
        'success',
        'error',
        'view',
        log_changes_status, # 'change'
        ('download' if active_storage_enabled),
        ('email' if email_enabled),
        ('sign_in' if sign_in_enabled),
        ('sign_out' if sign_out_enabled)
      ].compact

      additional = Array(additional_statuses).map { |status| status.to_s.downcase }

      base | additional # union
    )
  end

  def self.log_changes_status
    'change'.freeze
  end

  # This is set by the "set_effective_logging_current_user" before_filter.
  def self.current_user=(user)
    Thread.current[:effective_logging_current_user] = user
  end

  def self.current_user
    Thread.current[:effective_logging_current_user]
  end

  # Used to supress all logging
  def self.supressed=(value)
    Thread.current[:effective_logging_supressed] = value
  end

  def self.supressed(&block)
    Thread.current[:effective_logging_supressed] = true
    value = yield
    Thread.current[:effective_logging_supressed] = nil
    value
  end

  def self.supressed?
    Thread.current[:effective_logging_supressed] == true
  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
effective_logging-3.5.4 lib/effective_logging.rb
effective_logging-3.5.3 lib/effective_logging.rb
effective_logging-3.5.2 lib/effective_logging.rb
effective_logging-3.5.1 lib/effective_logging.rb
effective_logging-3.5.0 lib/effective_logging.rb
effective_logging-3.4.1 lib/effective_logging.rb
effective_logging-3.4.0 lib/effective_logging.rb
effective_logging-3.3.0 lib/effective_logging.rb