Class: Async::App::WebApps::MetricsApp::Serializer
- Inherits:
-
Object
- Object
- Async::App::WebApps::MetricsApp::Serializer
- Defined in:
- lib/async/app/web_apps/metrics_app/serializer.rb
Instance Method Summary collapse
-
#initialize(prefix:, store:) ⇒ Serializer
constructor
A new instance of Serializer.
- #metric_labels(value) ⇒ Object
- #metric_line(value) ⇒ Object
- #metric_name(value) ⇒ Object
- #serialize ⇒ Object
Constructor Details
#initialize(prefix:, store:) ⇒ Serializer
Returns a new instance of Serializer.
4 5 6 7 |
# File 'lib/async/app/web_apps/metrics_app/serializer.rb', line 4 def initialize(prefix:, store:) @prefix = prefix @store = store end |
Instance Method Details
#metric_labels(value) ⇒ Object
18 |
# File 'lib/async/app/web_apps/metrics_app/serializer.rb', line 18 def metric_labels(value) = value[:labels].map { |tag, tag_value| "#{tag}=#{tag_value.to_s.inspect}" }.join(",") |
#metric_line(value) ⇒ Object
20 21 22 |
# File 'lib/async/app/web_apps/metrics_app/serializer.rb', line 20 def metric_line(value) "#{metric_name(value)}{#{metric_labels(value)}} #{value[:value]}" if value.key?(:value) end |
#metric_name(value) ⇒ Object
16 |
# File 'lib/async/app/web_apps/metrics_app/serializer.rb', line 16 def metric_name(value) = "#{@prefix}_#{value[:name]}_#{value[:suffix]}" |
#serialize ⇒ Object
9 10 11 12 13 14 |
# File 'lib/async/app/web_apps/metrics_app/serializer.rb', line 9 def serialize @store.flat_map { metric_line(_1) } .compact .join("\n") .then { "#{_1}\n" } end |