class Checks

Constants

VERSION

Attributes

config_path[RW]

Public Class Methods

checkin(*args) click to toggle source
# File lib/checks.rb, line 13
def checkin(*args); instance.checkin(*args); end
checkin!(*args) click to toggle source
# File lib/checks.rb, line 14
def checkin!(*args); instance.checkin!(*args); end
manual_checkin(*args) click to toggle source
# File lib/checks.rb, line 12
def manual_checkin(*args); instance.manual_checkin(*args); end
new() click to toggle source
# File lib/checks.rb, line 17
def initialize
  self.config_path = defined?(Rails) ? Rails.root.join('config/checks.yml').to_s : 'config/checks.yml'
end

Public Instance Methods

checkin(*check) click to toggle source
# File lib/checks.rb, line 39
def checkin(*check)
  path = path_for *check
  invoke "http://hchk.io/#{path}" if path
end
checkin!(*check) click to toggle source
# File lib/checks.rb, line 44
def checkin!(*check)
  path = path_for *check
  raise ArgumentError.new("unknown check #{check.join(".")}") unless path
  invoke "http://hchk.io/#{path}"
end
config() click to toggle source
# File lib/checks.rb, line 26
def config
  @config ||= begin
    path = config_path.to_s
    return {} unless ::File.exist?(path)
    YAML.load_file(path).fetch('checks')
  end
end
config_path=(value) click to toggle source
# File lib/checks.rb, line 21
def config_path=(value)
  @config_path = value
  reload!
end
manual_checkin(path) click to toggle source
# File lib/checks.rb, line 50
def manual_checkin(path)
  invoke "http://hchk.io/#{path}"
end
reload!() click to toggle source
# File lib/checks.rb, line 34
def reload!
  @config = nil
  config
end

Private Instance Methods

invoke(url) click to toggle source
# File lib/checks.rb, line 56
def invoke(url)
  uri = URI.parse url
  Net::HTTP.post_form(uri, {})
end
path_for(*check) click to toggle source
# File lib/checks.rb, line 61
def path_for(*check)
  return unless check.any?
  base = config
  check.each do |path|
    return nil unless base.is_a?(Hash)
    base = base[path.to_s]
  end
  base
end