health 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ *.gem
21
+
22
+ ## PROJECT::SPECIFIC
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ health (0.0.1)
5
+ sinatra
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ rack (1.4.1)
11
+ rack-protection (1.2.0)
12
+ rack
13
+ sinatra (1.3.3)
14
+ rack (~> 1.3, >= 1.3.6)
15
+ rack-protection (~> 1.2)
16
+ tilt (~> 1.3, >= 1.3.3)
17
+ tilt (1.3.3)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ bundler (>= 1.0.0)
24
+ health!
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "health/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "health"
7
+ s.version = Health::VERSION
8
+ s.authors = ["James Golick"]
9
+ s.email = ["jamesgolick@gmail.com"]
10
+ s.description = "Health checks for rails."
11
+ s.summary = "Health checks for rails."
12
+ s.homepage = "https://github.com/jamesgolick/health"
13
+
14
+ s.require_paths = ["lib"]
15
+
16
+ s.rubyforge_project = "health"
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ["lib"]
22
+
23
+ # specify any dependencies here; for example:
24
+ s.add_development_dependency "bundler", ">= 1.0.0"
25
+
26
+ s.add_runtime_dependency "sinatra"
27
+ end
@@ -0,0 +1,31 @@
1
+ module Health
2
+ autoload :Checker, "health/checker"
3
+ autoload :Checks, "health/checks"
4
+ autoload :Endpoint, "health/endpoint"
5
+
6
+ class << self
7
+ def checker
8
+ @checker ||= Checker.new
9
+ end
10
+
11
+ def configure(&block)
12
+ checker.configure(&block)
13
+ end
14
+
15
+ def perform(name)
16
+ checker.perform(name)
17
+ end
18
+
19
+ def names
20
+ checker.names
21
+ end
22
+
23
+ def endpoint_access_policy(&block)
24
+ if block_given?
25
+ @endpoint_access_policy = block
26
+ else
27
+ @endpoint_access_policy ||= proc { true }
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ module Health
2
+ class Checker
3
+ def checks
4
+ @checks ||= {}
5
+ end
6
+
7
+ def configure(&block)
8
+ instance_eval(&block)
9
+ end
10
+
11
+ def check(name_or_object, &block)
12
+ if name_or_object.respond_to?(:call)
13
+ checks[name_or_object.name] = name_or_object
14
+ else
15
+ checks[name_or_object] = block
16
+ end
17
+ end
18
+
19
+ def names
20
+ checks.keys
21
+ end
22
+
23
+ def perform(name)
24
+ checks[name.to_sym].call.tap do |result|
25
+ assert_necessary_keys(result)
26
+ end
27
+ end
28
+
29
+ private
30
+ def assert_necessary_keys(result)
31
+ (result.has_key?(:ok) && result.has_key?(:output)) ||
32
+ raise("Check results MUST have :ok and :output keys.")
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module Health
2
+ module Checks
3
+ autoload :Rollout, "health/checks/rollout"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ module Health
2
+ module Checks
3
+ class Rollout
4
+ def initialize(rollout_name, rollout = $rollout)
5
+ @rollout_name = rollout_name
6
+ @rollout = rollout
7
+ end
8
+
9
+ def name
10
+ "#{@rollout_name}_rollout"
11
+ end
12
+
13
+ def call
14
+ {:ok => @rollout.active?(@rollout_name),
15
+ :output => @rollout.get(@rollout_name).to_hash}
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,26 @@
1
+ require "sinatra/base"
2
+
3
+ module Health
4
+ class Endpoint < Sinatra::Base
5
+ before do
6
+ content_type "application/json"
7
+
8
+ if !instance_eval(&Health.endpoint_access_policy)
9
+ halt "Access denied."
10
+ end
11
+ end
12
+
13
+ get "/" do
14
+ Health.names.to_json
15
+ end
16
+
17
+ get "/:name" do
18
+ pass if !Health.names.include?(params[:name].to_sym)
19
+
20
+ value = Health.perform(params[:name])
21
+ status = value[:ok] ? 200 : 500
22
+
23
+ [status, value.to_json]
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Health
2
+ VERSION = "0.0.2"
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: health
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-11-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70250669732000 !ruby/object:Gem::Requirement
16
+ requirement: &70364561163080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70250669732000
24
+ version_requirements: *70364561163080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sinatra
27
- requirement: &70250669731580 !ruby/object:Gem::Requirement
27
+ requirement: &70364561162660 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,14 +32,24 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70250669731580
35
+ version_requirements: *70364561162660
36
36
  description: Health checks for rails.
37
37
  email:
38
38
  - jamesgolick@gmail.com
39
39
  executables: []
40
40
  extensions: []
41
41
  extra_rdoc_files: []
42
- files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - Gemfile.lock
46
+ - health.gemspec
47
+ - lib/health.rb
48
+ - lib/health/checker.rb
49
+ - lib/health/checks.rb
50
+ - lib/health/checks/rollout.rb
51
+ - lib/health/endpoint.rb
52
+ - lib/health/version.rb
43
53
  homepage: https://github.com/jamesgolick/health
44
54
  licenses: []
45
55
  post_install_message: