rails-healthcheck 1.0.4 → 1.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93243a699dc2f935af3516530f2f2ef1e0878a228fb29dc188a99b75d79f1c18
4
- data.tar.gz: 876d3d9252ed1fb4c489d3f2227d1a283978a18619f266dfec238d45fe4d486d
3
+ metadata.gz: 0f365d0578746bf65bd75b360fbf3af46e3cba738a6eb9c9a3e88df133efee7c
4
+ data.tar.gz: e7c5d26b27e0f939a07e20a70f69dcac975ac9efc1d3ee06ec12d7a81f2f22dc
5
5
  SHA512:
6
- metadata.gz: 28b69c054262a373359500d270e831a5beaf184253c92283a004cce9b13cf68cc8b70bc9417571dfc91614a43f3e06630856b3ffae4725121b3f9749aeafab3b
7
- data.tar.gz: fde9c2623fa346ed3d46ed72b85c9cda0ff2e1106328fe01122e62e800dc3dd619170591b6871a2e66ac1a9425c2a83d5b684f0d72b7af75eb89f06949cc9eb2
6
+ metadata.gz: 8d1d0412ade72f8d0a06d9ce2160164109e0d21bbe3c7cf13c1798267ecf59746581671602b552d6d023514e70c435c986749b15575844b328e2403f23ab0230
7
+ data.tar.gz: 400bee85de2479a5ae575a54c085c597fee2b46709c0cfa1066d628d17bf46d511a92563834ae0007613bad885130895555b38ea0d2df2c61e2db8aa4e113d72
data/README.md CHANGED
@@ -18,7 +18,7 @@ gem 'rails-healthcheck'
18
18
  and run:
19
19
 
20
20
  ```
21
- rails healthcheck:install
21
+ rails generate healthcheck:install
22
22
  ```
23
23
 
24
24
  ## Settings
@@ -23,13 +23,17 @@ module Healthcheck
23
23
  end
24
24
 
25
25
  def success
26
- head Healthcheck.success
26
+ head Healthcheck.configuration.success
27
27
  end
28
28
 
29
29
  def error
30
- return head(Healthcheck.error) unless Healthcheck.verbose
30
+ return head(Healthcheck.configuration.error) unless Healthcheck.configuration.verbose
31
31
 
32
- render json: { code: Healthcheck.error, errors: checker.errors.as_json }, status: Healthcheck.error
32
+ render json: {
33
+ code: Healthcheck.configuration.error,
34
+ errors: checker.errors.as_json
35
+ },
36
+ status: Healthcheck.configuration.error
33
37
  end
34
38
  end
35
39
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators/base'
4
+
5
+ module Healthcheck
6
+ class InstallGenerator < Rails::Generators::Base
7
+ def create_initializer_file
8
+ create_file(
9
+ 'config/initializers/healthcheck.rb',
10
+ <<~HEALTHCHECK_INITIALIZER_TEXT
11
+ # frozen_string_literal: true
12
+
13
+ Healthcheck.configure do |config|
14
+ config.success = 200
15
+ config.error = 503
16
+ config.verbose = false
17
+ config.route = '/healthcheck'
18
+ config.method = :get
19
+
20
+ # -- Checks --
21
+ # config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
22
+ # config.add_check :migrations,-> { ActiveRecord::Migration.check_pending! }
23
+ # config.add_check :cache, -> { Rails.cache.read('some_key') }
24
+ # config.add_check :environments, -> { Dotenv.require_keys('ENV_NAME', 'ANOTHER_ENV') }
25
+ end
26
+ HEALTHCHECK_INITIALIZER_TEXT
27
+ )
28
+ route 'Healthcheck.routes(self)'
29
+ end
30
+ end
31
+ end
@@ -9,7 +9,7 @@ module Healthcheck
9
9
  end
10
10
 
11
11
  def check
12
- Healthcheck.checks.map { |c| Thread.new { execute(c) } }.each(&:join)
12
+ Healthcheck.configuration.checks.map { |c| Thread.new { execute(c) } }.each(&:join)
13
13
  end
14
14
 
15
15
  def errored?
@@ -3,7 +3,10 @@
3
3
  module Healthcheck
4
4
  class Router
5
5
  def self.mount(router)
6
- router.send(Healthcheck.method, Healthcheck.route => 'healthcheck/healthchecks#check')
6
+ router.send(
7
+ Healthcheck.configuration.method,
8
+ Healthcheck.configuration.route => 'healthcheck/healthchecks#check'
9
+ )
7
10
  end
8
11
  end
9
12
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Healthcheck
4
- VERSION = '1.0.4'
4
+ VERSION = '1.0.5'
5
5
  end
data/lib/healthcheck.rb CHANGED
@@ -9,21 +9,17 @@ require 'healthcheck/router'
9
9
  require 'healthcheck/engine'
10
10
 
11
11
  module Healthcheck
12
- require 'healthcheck/railtie' if defined?(Rails)
12
+ module_function
13
13
 
14
- Configuration::SETTINGS.each do |setting|
15
- send(:define_singleton_method, setting, -> { configuration.send(setting) })
16
- end
17
-
18
- def self.configure
14
+ def configure
19
15
  yield(configuration)
20
16
  end
21
17
 
22
- def self.configuration
18
+ def configuration
23
19
  @configuration ||= Configuration.new
24
20
  end
25
21
 
26
- def self.routes(router)
22
+ def routes(router)
27
23
  Healthcheck::Router.mount(router)
28
24
  end
29
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-healthcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - linqueta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-16 00:00:00.000000000 Z
11
+ date: 2019-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -131,15 +131,14 @@ extra_rdoc_files: []
131
131
  files:
132
132
  - README.md
133
133
  - app/controllers/healthcheck/healthchecks_controller.rb
134
+ - lib/generators/healthcheck/install_generator.rb
134
135
  - lib/healthcheck.rb
135
136
  - lib/healthcheck/check.rb
136
137
  - lib/healthcheck/checker.rb
137
138
  - lib/healthcheck/configuration.rb
138
139
  - lib/healthcheck/engine.rb
139
140
  - lib/healthcheck/error.rb
140
- - lib/healthcheck/railtie.rb
141
141
  - lib/healthcheck/router.rb
142
- - lib/healthcheck/tasks/setup.rake
143
142
  - lib/healthcheck/version.rb
144
143
  - lib/rails-healthcheck.rb
145
144
  homepage: https://github.com/linqueta/rails-healthcheck
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'healthcheck'
4
- require 'rails'
5
-
6
- module Healthcheck
7
- class Railtie < Rails::Railtie
8
- rake_tasks do
9
- Dir[File.join(File.dirname(__FILE__), 'tasks/*.rake')].each { |f| load f }
10
- end
11
- end
12
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'fileutils'
4
-
5
- INITIALIZER = 'config/initializers/healthcheck.rb'
6
- OLD_ROUTES = 'config/routes.rb'
7
- NEW_ROUTES = 'config/routes.rb.new'
8
- ROUTES_SETUP = ' Healthcheck.routes(self)'
9
- ROUTES_INIT = 'Rails.application.routes.draw do'
10
-
11
- namespace :healthcheck do
12
- desc 'Install the files and settings to the gem Healthcheck works'
13
- task :install do
14
- puts ' - invoke Rails::Healthcheck'
15
- create_initializer
16
- mount_route
17
- end
18
- end
19
-
20
- def create_initializer
21
- FileUtils.mkdir_p(File.dirname(INITIALIZER))
22
- File.open(INITIALIZER, 'w') { |file| file << settings }
23
- puts ' - create config/initializers/healthcheck.rb'
24
- end
25
-
26
- def mount_route
27
- return unless File.exist?(OLD_ROUTES)
28
-
29
- puts ' - modify config/routes.rb'
30
- File.open(NEW_ROUTES, 'w') do |new_routes|
31
- File.foreach(OLD_ROUTES) do |line|
32
- new_routes.puts(line)
33
- if line.strip == ROUTES_INIT
34
- new_routes.puts(ROUTES_SETUP)
35
- new_routes.puts ''
36
- end
37
- end
38
- end
39
-
40
- File.delete(OLD_ROUTES)
41
- File.rename(NEW_ROUTES, OLD_ROUTES)
42
- end
43
-
44
- def settings
45
- <<~SETTINGS
46
- # frozen_string_literal: true
47
-
48
- Healthcheck.configure do |config|
49
- config.success = 200
50
- config.error = 503
51
- config.verbose = false
52
- config.route = '/healthcheck'
53
- config.method = :get
54
-
55
- # -- Checks --
56
- # Check if the db is available
57
- # config.add_check :database, -> { ActiveRecord::Base.connection.execute('select 1') }
58
- # Check if the db is available and without pending migrations
59
- # config.add_check :migrations,-> { ActiveRecord::Migration.check_pending! }
60
- # Check if the cache is available
61
- # config.add_check :cache, -> { Rails.cache.read('some_key') }
62
- # Check if the application required envs are defined
63
- # config.add_check :environments, -> { Dotenv.require_keys('ENV_NAME', 'ANOTHER_ENV') }
64
- end
65
- SETTINGS
66
- end