Class: Metrics::Instruments::Gauge

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

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Gauge

Returns a new instance of Gauge.

Raises:

  • (ArgumentError)


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

def initialize(&block)
  raise ArgumentError, "a block is required" unless block_given?
  @block = block
end

Instance Method Details

#as_json(*_) ⇒ Object



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

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

#getObject



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

def get
  instance_exec(&@block)
end

#to_json(*_) ⇒ Object



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

def to_json(*_)
  as_json.to_json
end