Class: Sentiero::Reporter::Context
- Inherits:
-
Object
- Object
- Sentiero::Reporter::Context
- Defined in:
- lib/sentiero/reporter/context.rb
Overview
Immutable, string-keyed bag of report context. Keys are normalized to strings on construction and on every merge.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(hash = {}) ⇒ Context
constructor
A new instance of Context.
- #key?(key) ⇒ Boolean
- #merge(other) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(hash = {}) ⇒ Context
Returns a new instance of Context.
10 11 12 |
# File 'lib/sentiero/reporter/context.rb', line 10 def initialize(hash = {}) @data = Normalizer.stringify_shallow(hash).freeze end |
Instance Method Details
#[](key) ⇒ Object
18 |
# File 'lib/sentiero/reporter/context.rb', line 18 def [](key) = @data[key.to_s] |
#empty? ⇒ Boolean
22 |
# File 'lib/sentiero/reporter/context.rb', line 22 def empty? = @data.empty? |
#key?(key) ⇒ Boolean
20 |
# File 'lib/sentiero/reporter/context.rb', line 20 def key?(key) = @data.key?(key.to_s) |
#merge(other) ⇒ Object
14 15 16 |
# File 'lib/sentiero/reporter/context.rb', line 14 def merge(other) Context.new(@data.merge(Normalizer.stringify_shallow(to_hash(other)))) end |
#to_h ⇒ Object
24 |
# File 'lib/sentiero/reporter/context.rb', line 24 def to_h = @data.dup |