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 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
@@ -0,0 +1,9 @@
1
+ class What::Formatters::Base
2
+ def mime
3
+ raise "Formatter #{self.class.name} doesn't override 'mime'"
4
+ end
5
+
6
+ def format(_)
7
+ raise "Formatter #{self.class.name} doesn't override 'format'"
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class What::Formatters::JSON < What::Formatters::Base
2
+ def mime
3
+ 'application/json'
4
+ end
5
+
6
+ def format(hash)
7
+ JSON.unparse(hash) + "\n"
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class What::Formatters::YAML < What::Formatters::Base
2
+ def mime
3
+ 'application/x-yaml'
4
+ end
5
+
6
+ def format(hash)
7
+ hash.to_yaml
8
+ end
9
+ end
@@ -1,19 +1,23 @@
1
- class What::JsonFormatter
2
- def mime
3
- 'application/json'
4
- end
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
- def format(hash)
7
- JSON.unparse(hash) + "\n"
8
- end
9
- end
7
+ globs = [File.join(File.dirname(__FILE__), 'formatters', '*.rb')]
10
8
 
11
- class What::YamlFormatter
12
- def mime
13
- 'application/x-yaml'
14
- end
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
- def format(hash)
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::Config.formatter.mime},
11
- What::Config.formatter.format(What::Status.all)
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
@@ -1,3 +1,3 @@
1
1
  module What
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
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/status'
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: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
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-11 00:00:00 -07:00
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