Class: Metrics::Instruments::Gauge

Inherits:
Instrument show all
Defined in:
lib/ruby-metrics/instruments/gauge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Instrument

#tag, #tags

Constructor Details

#initialize(options = {}, &block) ⇒ Gauge

Returns a new instance of Gauge.

Raises:

  • (ArgumentError)


8
9
10
11
12
# File 'lib/ruby-metrics/instruments/gauge.rb', line 8

def initialize(options = {}, &block)
  raise ArgumentError, "a block is required" unless block_given?
  @block = block
  @units = options[:units]
end

Instance Attribute Details

#unitsObject (readonly)

Returns the value of attribute units.



6
7
8
# File 'lib/ruby-metrics/instruments/gauge.rb', line 6

def units
  @units
end

Instance Method Details

#as_json(*_) ⇒ Object



18
19
20
21
# File 'lib/ruby-metrics/instruments/gauge.rb', line 18

def as_json(*_)
  value = get
  value.respond_to?(:as_json) ? value.as_json : value
end

#getObject



14
15
16
# File 'lib/ruby-metrics/instruments/gauge.rb', line 14

def get
  instance_exec(&@block)
end

#to_json(*_) ⇒ Object



23
24
25
# File 'lib/ruby-metrics/instruments/gauge.rb', line 23

def to_json(*_)
  as_json.to_json
end