what 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/what/config.rb +0 -11
- data/lib/what/formatter.rb +20 -0
- data/lib/what/formatters/base.rb +9 -0
- data/lib/what/formatters/json.rb +9 -0
- data/lib/what/formatters/yaml.rb +9 -0
- data/lib/what/formatters.rb +18 -14
- data/lib/what/server.rb +3 -2
- data/lib/what/version.rb +1 -1
- data/lib/what.rb +5 -4
- metadata +8 -4
data/lib/what/config.rb
CHANGED
@@ -40,15 +40,4 @@ class What::Config
|
|
40
40
|
def self.all
|
41
41
|
@config
|
42
42
|
end
|
43
|
-
|
44
|
-
def self.formatter
|
45
|
-
@formatter ||= case @config['formatter']
|
46
|
-
when 'json'
|
47
|
-
What::JsonFormatter.new
|
48
|
-
when 'yaml'
|
49
|
-
What::YamlFormatter.new
|
50
|
-
else
|
51
|
-
What::JsonFormatter.new
|
52
|
-
end
|
53
|
-
end
|
54
43
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class What::Formatter
|
2
|
+
def self.use(name)
|
3
|
+
@formatter = case name
|
4
|
+
when 'json'
|
5
|
+
What::Formatters::JSON.new
|
6
|
+
when 'yaml'
|
7
|
+
What::Formatters::YAML.new
|
8
|
+
else
|
9
|
+
What::Formatters::JSON.new
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.mime
|
14
|
+
@formatter.mime
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.format(hash)
|
18
|
+
@formatter.format(hash)
|
19
|
+
end
|
20
|
+
end
|
data/lib/what/formatters.rb
CHANGED
@@ -1,19 +1,23 @@
|
|
1
|
-
|
2
|
-
def
|
3
|
-
|
4
|
-
|
1
|
+
module What::Formatters
|
2
|
+
def self.load_all
|
3
|
+
# load all formatters defined in what/formatters, in addition to any paths
|
4
|
+
# specified in the config file.
|
5
|
+
require 'what/formatters/base'
|
5
6
|
|
6
|
-
|
7
|
-
JSON.unparse(hash) + "\n"
|
8
|
-
end
|
9
|
-
end
|
7
|
+
globs = [File.join(File.dirname(__FILE__), 'formatters', '*.rb')]
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
if What::Config['formatter_paths']
|
10
|
+
What::Config['formatter_paths'].each do |formatter_path|
|
11
|
+
globs << File.join(What::Config['base'], formatter_path, '*.rb')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
globs.each do |glob|
|
16
|
+
Dir[glob].each do |fn|
|
17
|
+
require fn
|
18
|
+
end
|
19
|
+
end
|
15
20
|
|
16
|
-
|
17
|
-
hash.to_yaml
|
21
|
+
What::Formatter.use(What::Config['formatter'])
|
18
22
|
end
|
19
23
|
end
|
data/lib/what/server.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
class What::Server
|
2
2
|
def initialize
|
3
3
|
What::Modules.load_all
|
4
|
+
What::Formatters.load_all
|
4
5
|
What::Monitor.go!
|
5
6
|
end
|
6
7
|
|
7
8
|
def call(_)
|
8
9
|
[
|
9
10
|
What::Status[:health] != :alert ? 200 : 503,
|
10
|
-
{'Content-Type' => What::
|
11
|
-
What::
|
11
|
+
{'Content-Type' => What::Formatter.mime},
|
12
|
+
What::Formatter.format(What::Status.all)
|
12
13
|
]
|
13
14
|
end
|
14
15
|
end
|
data/lib/what/version.rb
CHANGED
data/lib/what.rb
CHANGED
@@ -6,11 +6,12 @@ require 'yaml'
|
|
6
6
|
require 'webrick'
|
7
7
|
require 'rack'
|
8
8
|
|
9
|
-
require 'what/version'
|
10
|
-
require 'what/helpers'
|
11
|
-
require 'what/formatters'
|
12
9
|
require 'what/config'
|
13
|
-
require 'what/
|
10
|
+
require 'what/formatter'
|
11
|
+
require 'what/formatters'
|
12
|
+
require 'what/helpers'
|
14
13
|
require 'what/modules'
|
15
14
|
require 'what/monitor'
|
16
15
|
require 'what/server'
|
16
|
+
require 'what/status'
|
17
|
+
require 'what/version'
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: what
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Ryan Lower
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-05-
|
19
|
+
date: 2011-05-16 00:00:00 -07:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -68,7 +68,11 @@ files:
|
|
68
68
|
- example/what.yml
|
69
69
|
- lib/what.rb
|
70
70
|
- lib/what/config.rb
|
71
|
+
- lib/what/formatter.rb
|
71
72
|
- lib/what/formatters.rb
|
73
|
+
- lib/what/formatters/base.rb
|
74
|
+
- lib/what/formatters/json.rb
|
75
|
+
- lib/what/formatters/yaml.rb
|
72
76
|
- lib/what/helpers.rb
|
73
77
|
- lib/what/modules.rb
|
74
78
|
- lib/what/modules/base.rb
|