Class: DogWatch::Model::Monitor
- Inherits:
-
Object
- Object
- DogWatch::Model::Monitor
- 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
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #initialize(name) ⇒ String constructor
- #message(message) ⇒ String
- #options(&block) ⇒ Hash
- #query(query) ⇒ String
- #tags(tags) ⇒ Array
- #type(type) ⇒ String
- #validate ⇒ DogWatch::Model::Response
Constructor Details
#initialize(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
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
17 18 19 |
# File 'lib/dogwatch/model/monitor.rb', line 17 def attributes @attributes end |
#name ⇒ Object (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
41 42 43 |
# File 'lib/dogwatch/model/monitor.rb', line 41 def () @attributes. = .to_s end |
#options(&block) ⇒ Hash
53 54 55 56 57 |
# File 'lib/dogwatch/model/monitor.rb', line 53 def (&block) opts = DogWatch::Model::Options.new(@monitor_type) opts.instance_eval(&block) @attributes. = opts.render end |
#query(query) ⇒ String
35 36 37 |
# File 'lib/dogwatch/model/monitor.rb', line 35 def query(query) @attributes.query = query.to_s end |
#tags(tags) ⇒ Array
47 48 49 |
# File 'lib/dogwatch/model/monitor.rb', line 47 def () @attributes. = .to_a end |
#type(type) ⇒ 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 |
#validate ⇒ DogWatch::Model::Response
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/dogwatch/model/monitor.rb', line 60 def validate return DogWatch::Model::Response.new(invalid_type_response, 'invalid') \ unless TYPE_MAP.key?(@monitor_type) errors = [] errors.push('Missing monitor type') if missing_type? errors.push('Missing monitor query') if missing_query? if errors.empty? DogWatch::Model::Response.new(['200', { :message => 'valid' }], 'valid') else DogWatch::Model::Response.new(['400', { 'errors' => errors }], 'invalid') end end |