Class: Itchy::VmcatcherEnv
- Inherits:
-
Object
- Object
- Itchy::VmcatcherEnv
- Defined in:
- lib/itchy/vmcatcher_env.rb
Overview
Wraps vmcatcher metadata taken from the environment.
Direct Known Subclasses
Constant Summary collapse
- REGISTERED_ENV_KEYS =
Dummy keys
[].freeze
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
-
.from_json(json) ⇒ Itchy::VmcatcherEnv
Creates an instance from a JSON document.
Instance Method Summary collapse
-
#initialize(env) ⇒ VmcatcherEnv
constructor
Creates an environment instance with pre-filtered attributes.
-
#to_hash ⇒ Hashie::Mash
Converts event attributes into a hash-like structure.
-
#to_json ⇒ String
Generates an ordinary JSON document from available ENV attributes.
-
#to_pretty_json ⇒ String
Generates a human-readable JSON document from available ENV attributes.
Constructor Details
#initialize(env) ⇒ VmcatcherEnv
Creates an environment instance with pre-filtered attributes.
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
#attributes ⇒ Object (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.
53 54 55 |
# File 'lib/itchy/vmcatcher_env.rb', line 53 def from_json(json) new ::JSON.parse(json) end |
Instance Method Details
#to_hash ⇒ Hashie::Mash
Converts event attributes into a hash-like structure.
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_json ⇒ String
Generates an ordinary JSON document from available ENV attributes.
34 35 36 |
# File 'lib/itchy/vmcatcher_env.rb', line 34 def to_json ::JSON.generate attributes end |
#to_pretty_json ⇒ String
Generates a human-readable JSON document from available ENV attributes.
26 27 28 |
# File 'lib/itchy/vmcatcher_env.rb', line 26 def to_pretty_json ::JSON.pretty_generate attributes end |