Class: Logtail::Contexts::User

Inherits:
Logtail::Context show all
Defined in:
lib/logtail/contexts/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ User

Returns a new instance of User.



10
11
12
13
14
# File 'lib/logtail/contexts/user.rb', line 10

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

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



8
9
10
# File 'lib/logtail/contexts/user.rb', line 8

def email
  @email
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/logtail/contexts/user.rb', line 8

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/logtail/contexts/user.rb', line 8

def name
  @name
end

Instance Method Details

#to_hashObject

Builds a hash representation containing simple objects, suitable for serialization (JSON).



17
18
19
20
21
22
23
24
25
# File 'lib/logtail/contexts/user.rb', line 17

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