Sha256: 7d3922de85e683a7a5467203f2bb9e58984061de54dd0654d94a530c99e025f6

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

module ModelLog
  module Default
    class Formatter
      include Helpers::Context

      def call
        return unless changed?
        content = []
        content += thread_content
        content += requester_content if requester
        content += user_content if current_user
        content += action_content
        content += resource_content
        content.join(ModelLog.config.separator)
      end

      private

      def thread_content
        [
          Thread.current.object_id
        ]
      end

      def requester_content
        [
          requester.request_method,
          requester.url,
          requester.referer,
          requester.remote_ip,
          requester.user_agent
        ]
      end

      def user_content
        [
          current_user.send(ModelLog.config.identity_field)
        ]
      end

      def action_content
        [
          action.upcase
        ]
      end

      def resource_content
        [
          resource.class.name,
          resource.id,
          changes
        ]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
model_log-2.0.1 lib/model_log/default/formatter.rb
model_log-2.0.0 lib/model_log/default/formatter.rb