lib/phi_attrs.rb in phi_attrs-0.1.4 vs lib/phi_attrs.rb in phi_attrs-0.2.0

- old
+ new

@@ -1,5 +1,7 @@ +# frozen_string_literal: true + require 'rails' require 'active_support' require 'request_store' require 'phi_attrs/version' @@ -9,28 +11,37 @@ require 'phi_attrs/logger' require 'phi_attrs/exceptions' require 'phi_attrs/phi_record' module PhiAttrs - def phi_model(with: nil, except: nil) - include PhiRecord - logger = ActiveSupport::Logger.new(PhiAttrs.log_path) - logger.formatter = Formatter.new - file_logger = ActiveSupport::TaggedLogging.new(logger) + def self.log_phi_access(user, message) + PhiAttrs::Logger.tagged(PHI_ACCESS_LOG_TAG, user) do + PhiAttrs::Logger.info(message) + end + end - PhiAttrs::Logger.logger = file_logger + module Model + def phi_model(with: nil, except: nil) + include PhiRecord + end end - @@log_path = nil + module Controller + extend ActiveSupport::Concern - def self.configure - yield self if block_given? - end + included do + before_action :record_i18n_data + end - def self.log_path - @@log_path - end + private - def self.log_path=(value) - @@log_path = value + def record_i18n_data + RequestStore.store[:phi_attrs_controller] = self.class.name + RequestStore.store[:phi_attrs_action] = params[:action] + + return if PhiAttrs.current_user_method.nil? + return unless respond_to?(PhiAttrs.current_user_method, true) + + RequestStore.store[:phi_attrs_current_user] = send(PhiAttrs.current_user_method) + end end end