Class: Timber::Contexts::Organization

Inherits:
Timber::Context
  • Object
show all
Defined in:
lib/timber/contexts/organization.rb

Overview

The organization context tracks the organization of the currently authenticated user.

You will want to add this context at the time you determine the organization a user belongs to, typically in the authentication flow.

Example:

organization_context = Timber::Contexts::Organization.new(id: "abc1234", name: "Timber Inc")
Timber::CurrentContext.with(organization_context) do
  # Logging will automatically include this context
  logger.info("This is a log message")
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Organization

Returns a new instance of Organization.



23
24
25
26
# File 'lib/timber/contexts/organization.rb', line 23

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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



21
22
23
# File 'lib/timber/contexts/organization.rb', line 21

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



21
22
23
# File 'lib/timber/contexts/organization.rb', line 21

def name
  @name
end

Instance Method Details

#as_json(_options = {}) ⇒ Object



28
29
30
# File 'lib/timber/contexts/organization.rb', line 28

def as_json(_options = {})
  {id: Timber::Util::Object.try(id, :to_s), name: name}
end