Class: Doggy::Models::Monitor

Inherits:
Doggy::Model show all
Defined in:
lib/doggy/models/monitor.rb

Defined Under Namespace

Classes: Options

Instance Attribute Summary

Attributes inherited from Doggy::Model

#is_deleted, #loading_source, #path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Doggy::Model

#==, accepted_response, all_local_resources, changed_resources, current_sha, #destroy, #destroy_local, emit_shipit_deployment, find, find_local, infer_type, #initialize, request, #save, #save_local, sort_by_key

Constructor Details

This class inherits a constructor from Doggy::Model

Class Method Details

.resource_url(id = nil) ⇒ Object



56
57
58
# File 'lib/doggy/models/monitor.rb', line 56

def self.resource_url(id = nil)
  ["https://app.datadoghq.com/api/v1/monitor", id].compact.join("/")
end

Instance Method Details

#ensure_managed_emoji!Object



64
65
66
67
68
# File 'lib/doggy/models/monitor.rb', line 64

def ensure_managed_emoji!
  return unless managed?
  return if name =~ /\xF0\x9F\x90\xB6/
  self.name += " \xF0\x9F\x90\xB6"
end

#ensure_read_only!Object



40
41
42
43
44
45
46
# File 'lib/doggy/models/monitor.rb', line 40

def ensure_read_only!
  if options
    options.locked = true
  else
    self.options = Options.new(locked: true)
  end
end

#human_edit_urlObject



92
93
94
# File 'lib/doggy/models/monitor.rb', line 92

def human_edit_url
  "https://#{Doggy.base_human_url}/monitors##{id}/edit"
end

#human_urlObject



88
89
90
# File 'lib/doggy/models/monitor.rb', line 88

def human_url
  "https://#{Doggy.base_human_url}/monitors##{id}"
end

#managed?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/doggy/models/monitor.rb', line 60

def managed?
  !(name =~ Doggy::DOG_SKIP_REGEX)
end

#prefixObject



36
37
38
# File 'lib/doggy/models/monitor.rb', line 36

def prefix
  'monitor'
end

#refute_read_only!Object



48
49
50
51
52
53
54
# File 'lib/doggy/models/monitor.rb', line 48

def refute_read_only!
  if options
    options.locked = false
  else
    self.options = Options.new(locked: false)
  end
end

#to_hObject



96
97
98
# File 'lib/doggy/models/monitor.rb', line 96

def to_h
  Doggy::Model.sort_by_key(super.merge(options: options.to_h))
end

#toggle_mute!(action, body = nil) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/doggy/models/monitor.rb', line 74

def toggle_mute!(action, body = nil)
  return unless %w[mute unmute].include?(action) && id
  attributes = request(:post, "#{resource_url(id)}/#{action}", body)
  if message = attributes['errors']
    Doggy.ui.error(message)
  else
    self.attributes = attributes
    if local_version = Doggy::Model.find_local(id)
      self.path = local_version.path
    end
    save_local
  end
end

#validateObject



70
71
72
# File 'lib/doggy/models/monitor.rb', line 70

def validate
  ensure_renotify_interval_valid
end