Sha256: 90927ae5fd98c11c3fcc84128e68810f18ef64de1283cfdbc7cc9f3792181ffd
Contents?: true
Size: 1.57 KB
Versions: 2
Compression:
Stored size: 1.57 KB
Contents
require 'ostruct' require_relative 'options' module DogWatch module Model ## # Handles monitor DSL methods and object validation ## class Monitor TYPE_MAP = { metric_alert: 'metric alert', service_check: 'service check', event_alert: 'event alert' }.freeze attr_reader :name attr_reader :attributes # @param [String] name # @return [String] def initialize(name) @attributes = OpenStruct.new @name = name end # @param [Symbol] type # @return [String] def type(type) @monitor_type = type @attributes.type = TYPE_MAP[type] end # @param [String] query # @return [String] def query(query) @attributes.query = query.to_s end # @param [String] message # @return [String] def message(message) @attributes.message = message.to_s end # @param [Array] tags # @return [Array] def tags(tags) @attributes.tags = tags.to_a end # @param [Proc] block # @return [Hash] def options(&block) opts = DogWatch::Model::Options.new(@monitor_type) opts.instance_eval(&block) @attributes.options = opts.render end # @return [TrueClass|FalseClass] def validate return false unless TYPE_MAP.value?(@attributes.type) return true unless @attributes.type.nil? || @attributes.type.empty? || @attributes.query.nil? || @attributes.query.empty? false end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dogwatch-1.0.5 | lib/dogwatch/model/monitor.rb |
dogwatch-1.0.4 | lib/dogwatch/model/monitor.rb |