Sha256: 8f4193d7cbf1bd953e4d716b4ad48e97de20a01232471d477603232a3b09640a

Contents?: true

Size: 1.83 KB

Versions: 20

Compression:

Stored size: 1.83 KB

Contents

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

module EffectiveLogging

  # The following are all valid config keys
  mattr_accessor :logs_table_name

  mattr_accessor :authorization_method
  mattr_accessor :layout
  mattr_accessor :additional_statuses

  mattr_accessor :email_enabled
  mattr_accessor :sign_in_enabled
  mattr_accessor :sign_out_enabled

  mattr_accessor :supressed

  def self.setup
    yield self
  end

  def self.authorized?(controller, action, resource)
    @_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact

    return !!authorization_method unless authorization_method.respond_to?(:call)
    controller = controller.controller if controller.respond_to?(:controller)

    begin
      !!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
    rescue *@_exceptions
      false
    end
  end

  def self.authorize!(controller, action, resource)
    raise Effective::AccessDenied unless authorized?(controller, action, resource)
  end

  def self.supressed(&block)
    @@supressed = true; yield; @@supressed = false
  end

  def self.supressed?
    @@supressed == true
  end

  def self.statuses
    @statuses ||= (
      Array(@@additional_statuses).map { |status| status.to_s.downcase } |  # union
      ['info', 'success', 'error', 'view', log_changes_status, ('email' if email_enabled), ('sign_in' if sign_in_enabled), ('sign_out' if sign_out_enabled)].compact
    )
  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)
    @effective_logging_current_user = user
  end

  def self.current_user
    @effective_logging_current_user
  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
effective_logging-3.0.12 lib/effective_logging.rb
effective_logging-3.0.11 lib/effective_logging.rb
effective_logging-3.0.10 lib/effective_logging.rb
effective_logging-3.0.9 lib/effective_logging.rb
effective_logging-3.0.8 lib/effective_logging.rb
effective_logging-3.0.7 lib/effective_logging.rb
effective_logging-3.0.6 lib/effective_logging.rb
effective_logging-3.0.5 lib/effective_logging.rb
effective_logging-3.0.4 lib/effective_logging.rb
effective_logging-3.0.3 lib/effective_logging.rb
effective_logging-3.0.2 lib/effective_logging.rb
effective_logging-3.0.1 lib/effective_logging.rb
effective_logging-3.0.0 lib/effective_logging.rb
effective_logging-2.1.2 lib/effective_logging.rb
effective_logging-2.1.1 lib/effective_logging.rb
effective_logging-2.1.0 lib/effective_logging.rb
effective_logging-2.0.8 lib/effective_logging.rb
effective_logging-2.0.7 lib/effective_logging.rb
effective_logging-2.0.6 lib/effective_logging.rb
effective_logging-2.0.5 lib/effective_logging.rb