Class: DogWatch::Model::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/dogwatch/model/monitor.rb

Overview

Handles monitor DSL methods and object validation

Constant Summary collapse

TYPE_MAP =
{
  metric_alert: 'metric alert',
  service_check: 'service check',
  event_alert: 'event alert'
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ String

Parameters:

  • name (String)


21
22
23
24
# File 'lib/dogwatch/model/monitor.rb', line 21

def initialize(name)
  @attributes = OpenStruct.new
  @name = name
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



17
18
19
# File 'lib/dogwatch/model/monitor.rb', line 17

def attributes
  @attributes
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/dogwatch/model/monitor.rb', line 16

def name
  @name
end

Instance Method Details

#message(message) ⇒ String

Parameters:

  • message (String)

Returns:

  • (String)


41
42
43
# File 'lib/dogwatch/model/monitor.rb', line 41

def message(message)
  @attributes.message = message.to_s
end

#options(&block) ⇒ Hash

Parameters:

  • block (Proc)

Returns:

  • (Hash)


53
54
55
56
57
# File 'lib/dogwatch/model/monitor.rb', line 53

def options(&block)
  opts = DogWatch::Model::Options.new(@monitor_type)
  opts.instance_eval(&block)
  @attributes.options = opts.render
end

#query(query) ⇒ String

Parameters:

  • query (String)

Returns:

  • (String)


35
36
37
# File 'lib/dogwatch/model/monitor.rb', line 35

def query(query)
  @attributes.query = query.to_s
end

#tags(tags) ⇒ Array

Parameters:

  • tags (Array)

Returns:

  • (Array)


47
48
49
# File 'lib/dogwatch/model/monitor.rb', line 47

def tags(tags)
  @attributes.tags = tags.to_a
end

#type(type) ⇒ String

Parameters:

  • type (Symbol)

Returns:

  • (String)


28
29
30
31
# File 'lib/dogwatch/model/monitor.rb', line 28

def type(type)
  @monitor_type = type
  @attributes.type = TYPE_MAP[type]
end

#validateTrueClass|FalseClass

Returns:

  • (TrueClass|FalseClass)


60
61
62
63
64
65
66
# File 'lib/dogwatch/model/monitor.rb', line 60

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