Class: TingYun::EnvironmentReport
- Inherits:
-
Object
- Object
- TingYun::EnvironmentReport
- Defined in:
- lib/ting_yun/environment_report.rb
Overview
The EnvironmentReport is responsible for analyzing the application’s environment and generating the data for the Environment Report in TINGYUN
It contains useful system information like Ruby version, OS, loaded gems, etc.
Additional logic can be registered by using the EnvironmentReport.report_on hook.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
- .registered_reporters ⇒ Object
-
.registered_reporters=(logic) ⇒ Object
allow the logic to be swapped out in tests.
-
.report_on(key, &block) ⇒ Object
This is the main interface for registering logic that should be included in the Environment Report.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize ⇒ EnvironmentReport
constructor
Generate the report based on the class level logic.
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ EnvironmentReport
Generate the report based on the class level logic.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ting_yun/environment_report.rb', line 95 def initialize @data = self.class.registered_reporters.inject(Hash.new) do |data, (key, logic)| begin value = logic.call if value data[key] = value else ::TingYun::Agent.logger.debug("EnvironmentReport ignoring value for #{key.inspect} which came back falsey: #{value.inspect}") end rescue => e ::TingYun::Agent.logger.debug("EnvironmentReport failed to retrieve value for #{key.inspect}: #{e}") end data end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
93 94 95 |
# File 'lib/ting_yun/environment_report.rb', line 93 def data @data end |
Class Method Details
.registered_reporters ⇒ Object
34 35 36 |
# File 'lib/ting_yun/environment_report.rb', line 34 def self.registered_reporters @registered_reporters ||= Hash.new end |
.registered_reporters=(logic) ⇒ Object
allow the logic to be swapped out in tests
39 40 41 |
# File 'lib/ting_yun/environment_report.rb', line 39 def self.registered_reporters=(logic) @registered_reporters = logic end |
.report_on(key, &block) ⇒ Object
This is the main interface for registering logic that should be included in the Environment Report. For example:
EnvironmentReport.report_on “Day of week” do
Time.now.strftime("%A")
end
The passed blocks will be run in EnvironmentReport instances on #initialize.
Errors raised in passed blocks will be handled and logged at debug, so it is safe to report on things that may not work in certain environments.
The blocks should only return strings or arrays full of strings. Falsey values will be ignored.
30 31 32 |
# File 'lib/ting_yun/environment_report.rb', line 30 def self.report_on(key, &block) registered_reporters[key] = block end |
Instance Method Details
#[](key) ⇒ Object
111 112 113 |
# File 'lib/ting_yun/environment_report.rb', line 111 def [](key) @data[key] end |
#[]=(key, value) ⇒ Object
115 116 117 |
# File 'lib/ting_yun/environment_report.rb', line 115 def []=(key, value) @data[key] = value end |
#to_a ⇒ Object
119 120 121 |
# File 'lib/ting_yun/environment_report.rb', line 119 def to_a @data.to_a end |