Sha256: da5a41a8e4b639845219dec031b7a6eae3549ed727b0b5e30a6e93752fcf005a

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

#let's inject some code into rails before and after the initialization
class Railtie < ::Rails::Railtie
  #auto load our observers folder before rails freeze this variable
  initializer 'activeservice.autoload', :before => :set_autoload_paths do |app|
    if File.directory?(Rails.root + "app/models/observers/oh_my_log")
      app.config.autoload_paths << "app/models/observers/oh_my_log"
    else
      p "Could not find the observers folder, did you use the task to generate them?"
    end
  end

  #now let's start our gem(only if there is an initializer) after the rails initialize process
  config.after_initialize do
    load Rails.root + "app/controllers/application_controller.rb"
    class ::ApplicationController
      before_action :get__session__info

      def get__session__info
        user = nil
        if defined?(current_user)
          user = current_user
        elsif defined?(current_admin_user)
          user = current_admin_user
        end
        Thread.current[:user] = user
        Thread.current[:remote_ip] = request.remote_ip
      end
    end
  end

  #time to add some tasks
  rake_tasks do
    load 'tasks/oh_my_log.rake'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
oh_my_log-1.0.3 lib/railtie.rb
oh_my_log-1.0.2 lib/railtie.rb