class Riemann::Experiment::Event

Attributes

attribute_names[RW]
protobuf[RW]

Public Class Methods

load(pb) click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 26
def self.load(pb)
  e = self.new()
  if !pb.is_a?(::Event)
    raise ArgumentError, "Not an Event protocol buffer object"
  end
  e.protobuf = pb
  pb.attributes.each {|a|
    e.attribute_set(a.key, a.value)
  }
  e
end
new() click to toggle source

Provide defaults on initialization

# File lib/riemann-ruby-experiments/event.rb, line 7
def initialize()
  @attrs = []
  @cached_attrs = {}
end

Public Instance Methods

add_tags(*tags) click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 131
def add_tags(*tags)
  @tags = [] if @tags.nil?
  tags.each {|t| @tags.push(t.to_s) }
end
attribute_get_value(name) { |name| ... } click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 51
def attribute_get_value(name)
  @cached_attrs.fetch(name) {
    a = protobuf.attributes&.detect {|a| a.key == name }
    if !a.nil?
      @cached_attrs[name] = a.value
      retval = a.value
    else
      retval = yield(name) if block_given?
    end
    retval
  }
end
attribute_set(name, value) click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 38
def attribute_set(name, value)
  if attribute_get_value(name)
    a = protobuf.attributes&.detect {|a| a.key == name }
    a.value = value
  else
    a = Attribute.new
    a.key = name
    a.value = value
    protobuf.attributes << a
  end
  @cached_attrs[name] = value
end
build(**fields) click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 20
def build(**fields)
  fields.each_pair {|k, v|
    self.send("#{k}=".to_sym, v)
  }
end
description() click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 117
def description
  d = protobuf.description
  d != "" ? d : nil
end
description=(d) click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 113
def description=(d)
  protobuf.description = d.to_s
end
dump()
Alias for: to_s
each_attribute() { |key, value| ... } click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 64
def each_attribute
  return enum_for(:each_attribute) unless block_given?
  protobuf.attributes.each {|a|
    yield(a.key, a.value)
  }
end
host() click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 108
def host
  h = protobuf.host
  h != "" ? h : nil
end
host=(host) click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 104
def host=(host)
  protobuf.host = host.to_s
end
maybe_apply_defaults() click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 153
def maybe_apply_defaults
  if protobuf.service == ""
    @service ||= "#{$0};#{$PID}"
    protobuf.service = @service
  end
  if protobuf.host == ""
    protobuf.host = @host
  end

  if !@tags.nil?
    protobuf.tags = @tags
  end
  if !@ttl.nil?
    protobuf.ttl = @ttl
  end
end
method_missing(m, *rest, &blk) click to toggle source
Calls superclass method
# File lib/riemann-ruby-experiments/event.rb, line 190
def method_missing(m, *rest, &blk)
  ms = m.to_s
  if ms.end_with?("=") && ms.length >= 2
    attribute_set(ms[0..-2], rest.first.to_s)
  else
    val = attribute_get_value(ms)
    if val.nil?
      super
    else
      val
    end
  end
end
metric() click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 149
def metric
  protobuf.metric_sint64 || protobuf.metric_d || protobuf.metric_f
end
metric=(m) click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 140
def metric=(m)
  case m
  when Integer
    protobuf.metric_sint64 = m
  when Float
    protobuf.metric_d = m
  end  # BigDecimal? Anything else?
end
respond_to?(m, include_private = false) click to toggle source
Calls superclass method
# File lib/riemann-ruby-experiments/event.rb, line 178
def respond_to?(m, include_private = false)
  ms = m.to_s
  mnoeq = ms[0..-2]
  if ms.end_with?("=") && ms.length >= 2
    true
  elsif attribute_get_value(ms)
    true
  else
    super
  end
end
service() click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 90
def service
  s = protobuf.service
  (s != "") ? s : nil
end
service=(service) click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 86
def service=(service)
  protobuf.service = service.to_s
end
setup(client) click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 12
def setup(client)
  @service = client&.default_service
  @host = client&.default_host
  @tags = client&.default_tags
  @ttl = client&.default_ttl
  @protobuf = ::Event.new
end
state() click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 99
def state
  s = protobuf.state
  (s != "") ? s : nil
end
state=(s) click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 95
def state=(s)
  protobuf.state = s
end
tags() click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 136
def tags
  protobuf.tags
end
time() click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 82
def time
  Time.at(protobuf.time)
end
time=(time) click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 71
def time=(time)
  case time
  when ::Time
    protobuf.time = time.to_i
  when ::DateTime
    protobuf.time = time.to_time.to_i
  else
    protobuf.time = time
  end
end
to_s() click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 170
def to_s
  maybe_apply_defaults
  protobuf.to_s
end
Also aliased as: to_sym, dump
to_sym()
Alias for: to_s
ttl() click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 126
def ttl
  t = protobuf.ttl
  t != "" ? t : nil
end
ttl=(ttl) click to toggle source
# File lib/riemann-ruby-experiments/event.rb, line 122
def ttl=(ttl)
  protobuf.ttl = ttl.to_f
end