Sha256: c9ec1aad8853970b67ebd93955d590ca235bd17ccccacee3ec87b11dea0762f4

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require 'yaml'
require 'open-uri'

def eval_and_fetch_constants(x)
  old = Module.constants.map{|c| c.to_s}
  eval(x)
  new = (Module.constants.map{|c| c.to_s} - old)
  new.map{|const| const_get(const) }
end

class Scout
  class Plugin
    def report(metrics)
      metrics.each do |key, value|
        send_report "#{self.class}.#{key}", value
      end
    end
  end

  def self.plugins(code)
    constants = eval_and_fetch_constants(code)
    constants.select{|constant| constant.instance_methods.map{|m| m.to_sym }.include?(:build_report) }
  end
end

module Deputy
  VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip

  def self.run_plugins
    content = get("/plugins.rb")
    Scout.plugins(content).each{|p| p.new.build_report }
  end

  def self.send_report(metric, value)
    get "/report/#{metric}/#{value}"
  end

  def self.get(path)
    url = "#{sheriff_url}#{path}"
    open(url).read
  rescue => e
    e.message << url
    raise e
  end

  def self.sheriff_url
    config['sheriff_url'].sub(%r{/$},'')
  end

  def self.config
    file = File.expand_path('~/.deputy.yml')
    YAML.load(File.read(file))
  rescue => e
    e.message << " -- do you have a #{file} ?"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
deputy-0.1.1 lib/deputy.rb