Sha256: 99dd4092a83a67bd343212d54110751c1acc54ec1ad4872783b317b0232a69bd
Contents?: true
Size: 1.51 KB
Versions: 1
Compression:
Stored size: 1.51 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 def self.start_oh_my_log if defined?(Mongoid) require 'mongoid-observers' require_relative "oh_my_log/mongoid_observer" end begin require Rails.root + "config/initializers/oh_my_log_initializer.rb" ::OhMyLog::ObserverFactory.activate_observers rescue return "could not start the gem, did you run oh_my_log:install ?" end end #time to add some tasks rake_tasks do load 'tasks/oh_my_log.rake' end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
oh_my_log-1.0.1 | lib/railtie.rb |