module EitilWrapper class Railtie < Rails::Railtie # Dynamic dispatching after initialization of Rails classes. initializer "my_railtie.configure_rails_initialization", options: :after do |app| if Object.const_defined?('EitilWrapper::Scopes::DefaultScopes') ::ApplicationRecord.send(:extend, EitilWrapper::Scopes::DefaultScopes) end if Object.const_defined?('EitilWrapper::Callbacks::HelperMethods') ::ApplicationRecord.send(:extend, EitilWrapper::Callbacks::HelperMethods) end if Object.const_defined?('EitilWrapper::CreateSingleMethodJob') # ISSUE: this code is currently defined eitil_wrapper/railtie.rb, since module inclusion # somehow leads to errors in the initialization process. Ideally, this code would be # defined in eitil_wrapper/jobs/single_method_job.rb and dispatched in eitil_wrapper/railtie.rb # BEWARE: _self is currently not accepted in perform_later jobs due to serialization errors # BEWARE: The cases of 'id' and '_self' both handle instances, with the difference # being that 'id' works for objects that have a database record, while '_self' # works for non database supported instanes, such as an Exporter instance. module ::EitilWrapper class SingleMethodJob < ::ApplicationJob def perform(*args, _class:, _method:, id: nil, _self: nil, **kwargs) object = if id _class.constantize.find(id) elsif _self _self else _class.constantize end if args.present? and kwargs.present? object.send _method, *args, **kwargs elsif args.present? object.send _method, *args elsif kwargs.present? object.send _method, **kwargs else object.send _method end end; end; end; end if Object.const_defined?('EitilWrapper::RequestLogger::CreateLoggerJob') module ::EitilWrapper module RequestLogger class LoggerJob < ::ApplicationJob def perform(logger_object) # set path for logger $request_logger_path ||= "#{Rails.root}/log/request_logger.log" # create logger, if not present if Dir[$request_logger_path].blank? || $request_logger.blank? $request_logger = Logger.new($request_logger_path) end # add logger_object to logger $request_logger.info(logger_object) end; end; end; end; end end end end