Sha256: ac550ba1cfcd5ea08770c4949b27e881910c7a8314a50ded104a1395eaae0ac5

Contents?: true

Size: 992 Bytes

Versions: 5

Compression:

Stored size: 992 Bytes

Contents

module Timber
  module Contexts
    # The user context tracks the currently authenticated user.
    #
    # You will want to add this context at the time log the user in, typically
    # during the authentication flow.
    #
    # Note: Timber will attempt to automatically add this if you add a #current_user
    # method to your controllers. Most authentication solutions do this for you automatically.
    #
    # Example:
    #
    #   user_context = Timber::Contexts::User.new(id: "abc1234", name: "Ben Johnson")
    #   Timber::CurrentContext.with(user_context) do
    #     # Logging will automatically include this context
    #     logger.info("This is a log message")
    #   end
    #
    class User < Context
      attr_reader :id, :name

      def initialize(attributes)
        @id = attributes[:id]
        @name = attributes[:name]
      end

      def keyspace
        :user
      end

      def as_json(_options = {})
        {id: id, name: name}
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
timber-1.0.3 lib/timber/contexts/user.rb
timberio-1.0.3 lib/timber/contexts/user.rb
timberio-1.0.2 lib/timber/contexts/user.rb
timberio-1.0.1 lib/timber/contexts/user.rb
timberio-1.0.0 lib/timber/contexts/user.rb