Sha256: af77711b120aea7772f84baffb3ccfa266a56027928d064a11bb47dabd6c09e7

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

module EffectiveLogging
  class Engine < ::Rails::Engine
    engine_name 'effective_logging'

    # Set up our default configuration options.
    initializer "effective_logging.defaults", :before => :load_config_initializers do |app|
      eval File.read("#{config.root}/lib/generators/templates/effective_logging.rb")
    end

    # ActiveAdmin (optional)
    # This prepends the load path so someone can override the assets.rb if they want.
    initializer 'effective_logging.active_admin' do
      if defined?(ActiveAdmin) && EffectiveLogging.use_active_admin == true
        ActiveAdmin.application.load_paths.unshift Dir["#{config.root}/active_admin"]
      end
    end

    # Automatically Log Emails
    initializer 'effective_logging.emails' do |app|
      if EffectiveLogging.emails_enabled == true
        require 'effective_logging/email_logger'
        ActionMailer::Base.register_observer(EffectiveLogging::EmailLogger)
      end
    end

    # Register the log_page_views concern so that it can be called in ActionController or elsewhere
    initializer 'effective_logging.action_controller' do |app|
      ActiveSupport.on_load :action_controller do
        ActionController::Base.extend(EffectiveLogging::LogPageViews::ActionController)
      end
    end

    # This has to be run after initialization or User hasn't been loaded yet
    config.after_initialize do
      if EffectiveLogging.user_logins_enabled == true
        ActiveSupport.on_load :active_record do
          if defined?(Devise)
            User.instance_eval do
              alias_method :original_after_database_authentication, :after_database_authentication
              define_method(:after_database_authentication) { Effective::UserLogger.successful_login(self) ; original_after_database_authentication() }
            end
          else
            raise ArgumentError.new("EffectiveLogging.user_logins_enabled only works with Devise and a user class defined as User")
          end
        end
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
effective_logging-1.0.0 lib/effective_logging/engine.rb