Sha256: 538e19715c26216972dc08a3b236fe9c075b9de069e509f7e751c9fda8ccad52

Contents?: true

Size: 831 Bytes

Versions: 1

Compression:

Stored size: 831 Bytes

Contents

module Timber
  module Contexts
    class User < Context
      ROOT_KEY = :user.freeze
      VERSION = 1.freeze

      attr_reader :user

      def email
        return @email if defined?(@email)
        @email = user.respond_to?(:email) ? user.email : nil
      end

      def id
        return @id if defined?(@id)
        @id = user.respond_to?(:id) ? user.id : nil
      end

      def name
        return @name if defined?(@name)
        @name = user.respond_to?(:name) ? user.name : nil
      end

      def valid?
        !user.nil?
      end

      private
        def json_payload
          @json_payload ||= Macros::DeepMerger.merge({
            # order is relevant for logfmt styling
            :id => id,
            :name => name,
            :email => email
          }, super).freeze
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
timberio-1.0.0.beta1 lib/timber/contexts/user.rb