Class: Itchy::VmcatcherEnv

Inherits:
Object
  • Object
show all
Defined in:
lib/itchy/vmcatcher_env.rb

Overview

Wraps vmcatcher metadata taken from the environment.

Direct Known Subclasses

VmcatcherConfiguration, VmcatcherEvent

Constant Summary collapse

REGISTERED_ENV_KEYS =

Dummy keys

[].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ VmcatcherEnv

Creates an environment instance with pre-filtered attributes.

Parameters:

  • env (Object)

    hash-like or JSON-like object storing the raw environment



13
14
15
16
17
18
19
20
# File 'lib/itchy/vmcatcher_env.rb', line 13

def initialize(env)
  env = ::JSON.parse(env) if env.is_a?(String)

  @attributes = Itchy::Helpers::VmcatcherEnvHelper.select_from_env(
    env,
    self.class::REGISTERED_ENV_KEYS
  )
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



7
8
9
# File 'lib/itchy/vmcatcher_env.rb', line 7

def attributes
  @attributes
end

Class Method Details

.from_json(json) ⇒ Itchy::VmcatcherEnv

Creates an instance from a JSON document.

Parameters:

  • json (String)

    JSON to create an instance from

Returns:



53
54
55
# File 'lib/itchy/vmcatcher_env.rb', line 53

def from_json(json)
  new ::JSON.parse(json)
end

Instance Method Details

#to_hashHashie::Mash

Converts event attributes into a hash-like structure.

Returns:

  • (Hashie::Mash)

    hash-like structure with metadata



42
43
44
45
46
# File 'lib/itchy/vmcatcher_env.rb', line 42

def to_hash
  attr_converted = ::Hashie::Mash.new
  attributes.each_pair { |name, val| attr_converted[name.downcase] = val }
  attr_converted
end

#to_jsonString

Generates an ordinary JSON document from available ENV attributes.

Returns:

  • (String)

    JSON document



34
35
36
# File 'lib/itchy/vmcatcher_env.rb', line 34

def to_json
  ::JSON.generate attributes
end

#to_pretty_jsonString

Generates a human-readable JSON document from available ENV attributes.

Returns:

  • (String)

    pretty JSON document



26
27
28
# File 'lib/itchy/vmcatcher_env.rb', line 26

def to_pretty_json
  ::JSON.pretty_generate attributes
end