Module: CityWatch

Defined in:
lib/version.rb,
lib/city_watch.rb,
lib/city_watch/collector.rb,
lib/city_watch/commander.rb

Constant Summary collapse

VERSION =
"0.7.9"
Routes =
Rack::Mount::RouteSet.new

Class Method Summary collapse

Class Method Details

.configObject



24
25
26
27
28
29
30
31
32
# File 'lib/city_watch.rb', line 24

def self.config
	@config ||= {
		:watch_collector => "localhost:62000",
		:watch_commander => "localhost:62001",
		:environment => "development",
		:prefix => "CityWatch",
		:redis => {}
	}
end

.config_opts(conf, *opts) ⇒ Object



59
60
61
62
63
64
# File 'lib/city_watch.rb', line 59

def self.config_opts(conf,*opts)
	opts.inject({}) do |a,k|
		a[k] = conf[k]
		a
	end
end

.configureObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/city_watch.rb', line 3

def self.configure
	require 'optparse'
	options = {
		:config_file => "/etc/#{File.basename($0)}.conf",
	}
	OptionParser.new do |opts|
	  opts.banner = "Usage: city_watch [options]"
	  opts.on("-c", "--config [FILE]", "Specify config file.") do |config|
	    options[:config_file] = config
	  end
	end.parse!
	
	if File.exists?(options[:config_file])
		require 'yaml'
		config.merge!(YAML.load(IO.read(options[:config_file])) || {})
	end
	
	puts config if debug?
	
end

.debug?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/city_watch.rb', line 34

def self.debug?
	config[:debug] || false
end

.headerObject



66
67
68
# File 'lib/city_watch.rb', line 66

def self.header
	'<html><head><link rel="stylesheet" href="/stylesheets/city_watch.css"><link rel="stylesheet" href="/stylesheets/default.css"><script src="/javascripts/city_watch.js"></script><script src="/javascripts/highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body>'
end

.redisObject



54
55
56
57
# File 'lib/city_watch.rb', line 54

def self.redis
	require 'redis'
	@redis ||= ::Redis.new(config_opts(config[:redis], :path, :db, :password))
end

.unicorn_opts(rackup_opts) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/city_watch.rb', line 38

def self.unicorn_opts(rackup_opts)
	unless config[:unicorn]
		if config[File.basename($0).to_sym]
			config[:unicorn] = {:port => config[File.basename($0).to_sym].gsub(/.*:/,'')}
		end
	end
	if config[:unicorn]
		if config[:unicorn][:port]
			rackup_opts[:port] = config[:unicorn][:port]
			rackup_opts[:set_listener] = true
		end
		rackup_opts[:daemonize] = config[:unicorn][:config_file] || false
		rackup_opts[:options][:config_file] = config[:unicorn][:config_file] if config[:unicorn][:config_file]
	end
end