Sha256: db22455e8d97c9b936300ff78ce286988382b533d53e7367045ae715aa2b9ca3

Contents?: true

Size: 638 Bytes

Versions: 2

Compression:

Stored size: 638 Bytes

Contents

require "timber/context"
require "timber/util"

module Timber
  module Contexts
    # @private
    class User < Context
      attr_reader :id, :name, :email

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

      # Builds a hash representation containing simple objects, suitable for serialization (JSON).
      def to_hash
        @to_hash ||= {
          user: Util::NonNilHashBuilder.build do |h|
            h.add(:id, id)
            h.add(:name, name)
            h.add(:email, email)
          end
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
timber-3.0.1 lib/timber/contexts/user.rb
timber-3.0.0 lib/timber/contexts/user.rb