class DogWatch::Model::Options

Handles the options block methods

Constants

MONITOR_TYPE_OPTIONS_MAP

Attributes

attributes[R]

Public Class Methods

new(monitor_type = nil) click to toggle source

@param [Symbol] monitor_type the monitor type of monitor these

options belong to. This is used to validate monitor type
specific options such as thresholds.
# File lib/dogwatch/model/options.rb, line 19
def initialize(monitor_type = nil)
  @attributes = OpenStruct.new
  @monitor_type = monitor_type
end

Public Instance Methods

escalation_message(message) click to toggle source

@param [String] message

# File lib/dogwatch/model/options.rb, line 60
def escalation_message(message)
  @attributes.escalation_message = message.to_s
end
evaluation_delay(minutes) click to toggle source

@param [Integer] minutes

# File lib/dogwatch/model/options.rb, line 55
def evaluation_delay(minutes)
  @attributes.evaluation_delay = minutes.to_i
end
include_tags(include = true) click to toggle source

@param [Boolean] include

# File lib/dogwatch/model/options.rb, line 70
  def include_tags(include = true)
    @attributes.include_tags = !!include
  end

  # @param [Hash{String=>Fixnum}] thresholds
  def thresholds(thresholds)
    validate_monitor_type_specific_option!(:thresholds)
    @attributes.thresholds = thresholds
  end

  private

  def validate_monitor_type_specific_option!(option)
    options = Array(MONITOR_TYPE_OPTIONS_MAP[@monitor_type])
    return true if options.include?(option)

    # rubocop:disable Metrics/LineLength
    message = "The #{@monitor_type.inspect} monitor type does not support #{option.inspect}."
    message << " Did you mean one of #{options.join(', ')}?" if options.any?
    raise NotImplementedError, message
  end
end
no_data_timeframe(minutes) click to toggle source

@param [Integer] minutes

# File lib/dogwatch/model/options.rb, line 40
def no_data_timeframe(minutes)
  @attributes.no_data_timeframe = minutes.to_i
end
notify_audit(notify = false) click to toggle source

@param [Boolean] notify

# File lib/dogwatch/model/options.rb, line 65
def notify_audit(notify = false)
  @attributes.notify_audit = !!notify
end
notify_no_data(notify = false) click to toggle source

@param [Boolean] notify

# File lib/dogwatch/model/options.rb, line 35
def notify_no_data(notify = false)
  @attributes.notify_no_data = !!notify
end
render() click to toggle source

@return [Hash]

# File lib/dogwatch/model/options.rb, line 25
def render
  @attributes.each_pair.to_h
end
renotify_interval(minutes) click to toggle source

@param [Integer] minutes

# File lib/dogwatch/model/options.rb, line 50
def renotify_interval(minutes)
  @attributes.renotify_interval = minutes.to_i
end
silenced(args) click to toggle source

@param [Hash] args

# File lib/dogwatch/model/options.rb, line 30
def silenced(args)
  @attributes.silenced = args.to_h
end
thresholds(thresholds) click to toggle source

@param [Hash{String=>Fixnum}] thresholds

# File lib/dogwatch/model/options.rb, line 75
def thresholds(thresholds)
  validate_monitor_type_specific_option!(:thresholds)
  @attributes.thresholds = thresholds
end
timeout_h(hours) click to toggle source

@param [Integer] hours

# File lib/dogwatch/model/options.rb, line 45
def timeout_h(hours)
  @attributes.timeout_h = hours.to_i
end
validate_monitor_type_specific_option!(option) click to toggle source
# File lib/dogwatch/model/options.rb, line 82
def validate_monitor_type_specific_option!(option)
  options = Array(MONITOR_TYPE_OPTIONS_MAP[@monitor_type])
  return true if options.include?(option)

  # rubocop:disable Metrics/LineLength
  message = "The #{@monitor_type.inspect} monitor type does not support #{option.inspect}."
  message << " Did you mean one of #{options.join(', ')}?" if options.any?
  raise NotImplementedError, message
end