Class: Timber::Contexts::Organization
- Inherits:
-
Timber::Context
- Object
- Timber::Context
- Timber::Contexts::Organization
- 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")
logger.with_context(organization_context) do
# Logging will automatically include this context
logger.info("This is a log message")
end
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#as_json(_options = {}) ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
-
#initialize(attributes) ⇒ Organization
constructor
A new instance of Organization.
Constructor Details
#initialize(attributes) ⇒ Organization
Returns a new instance of Organization.
26 27 28 29 |
# File 'lib/timber/contexts/organization.rb', line 26 def initialize(attributes) @id = Timber::Util::Object.try(attributes[:id], :to_s) @name = attributes[:name] end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
24 25 26 |
# File 'lib/timber/contexts/organization.rb', line 24 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/timber/contexts/organization.rb', line 24 def name @name end |
Instance Method Details
#as_json(_options = {}) ⇒ Object
Builds a hash representation containing simple objects, suitable for serialization (JSON).
32 33 34 |
# File 'lib/timber/contexts/organization.rb', line 32 def as_json( = {}) {id: id, name: name} end |