Class: Sciosano::Context
- Inherits:
-
Object
- Object
- Sciosano::Context
- Defined in:
- lib/sciosano/context.rb
Overview
Context holds user, tags, and extra data for reports
Instance Attribute Summary collapse
-
#extra ⇒ Object
Returns the value of attribute extra.
-
#request ⇒ Object
Returns the value of attribute request.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#user ⇒ Object
Returns the value of attribute user.
Instance Method Summary collapse
-
#dup ⇒ Context
Duplicate context.
-
#initialize ⇒ Context
constructor
A new instance of Context.
-
#merge(other) ⇒ Context
Merge additional context.
-
#merge!(other) ⇒ self
Merge additional context in place.
-
#to_h ⇒ Hash
Convert to hash.
Constructor Details
#initialize ⇒ Context
Returns a new instance of Context.
8 9 10 11 12 13 |
# File 'lib/sciosano/context.rb', line 8 def initialize @user = nil = {} @extra = {} @request = nil end |
Instance Attribute Details
#extra ⇒ Object
Returns the value of attribute extra.
6 7 8 |
# File 'lib/sciosano/context.rb', line 6 def extra @extra end |
#request ⇒ Object
Returns the value of attribute request.
6 7 8 |
# File 'lib/sciosano/context.rb', line 6 def request @request end |
#tags ⇒ Object
Returns the value of attribute tags.
6 7 8 |
# File 'lib/sciosano/context.rb', line 6 def end |
#user ⇒ Object
Returns the value of attribute user.
6 7 8 |
# File 'lib/sciosano/context.rb', line 6 def user @user end |
Instance Method Details
#dup ⇒ Context
Duplicate context
46 47 48 49 50 51 52 53 |
# File 'lib/sciosano/context.rb', line 46 def dup new_context = Context.new new_context.user = @user&.dup new_context. = .dup new_context.extra = @extra.dup new_context.request = @request&.dup new_context end |
#merge(other) ⇒ Context
Merge additional context
19 20 21 |
# File 'lib/sciosano/context.rb', line 19 def merge(other) dup.merge!(other) end |
#merge!(other) ⇒ self
Merge additional context in place
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/sciosano/context.rb', line 27 def merge!(other) case other when Context @user = other.user if other.user .merge!(other.) @extra.merge!(other.extra) @request = other.request if other.request when Hash @user = other[:user] if other[:user] .merge!(other[:tags] || {}) @extra.merge!(other[:extra] || {}) @request = other[:request] if other[:request] end self end |
#to_h ⇒ Hash
Convert to hash
58 59 60 61 62 63 64 65 |
# File 'lib/sciosano/context.rb', line 58 def to_h { user: user, tags: , extra: extra, request: request }.compact end |