Class: Sentiero::Reporter::Context

Inherits:
Object
  • Object
show all
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

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

Returns:

  • (Boolean)


22
# File 'lib/sentiero/reporter/context.rb', line 22

def empty? = @data.empty?

#key?(key) ⇒ Boolean

Returns:

  • (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_hObject



24
# File 'lib/sentiero/reporter/context.rb', line 24

def to_h = @data.dup