active_status 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d73120fdb2c6678c393901193462d336ee9f610cd14337efd0303719d0c9badc
4
+ data.tar.gz: a5bbe644b5e4c2656753beba09858263d31263890288b26b6b68b464bae98254
5
+ SHA512:
6
+ metadata.gz: 403e849b33d8228139fd0a49c927e1347c63d659bad078156a0aa423a4246bef76820c78274ec37e9dd72b501f4e8f68ddb7ff6d9427989dc305b0e09c6759fa
7
+ data.tar.gz: 7958be692b57f4d01d47630b3c5c6823f25b5ff388971d28f7a745d50235a5ed7440361e0391bcd4cb99a553359e544da83cf715651ef4b6b8f77d83fc32581e
@@ -0,0 +1,28 @@
1
+ # ActiveStatus
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'active_status'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install active_status
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,14 @@
1
+ module ActiveStatus
2
+ class ApplicationController < ActionController::API
3
+ def status
4
+ report = ActiveStatus::Report.new
5
+ report.build
6
+
7
+ if report.success?
8
+ head ActiveStatus.configuration.success
9
+ else
10
+ render json: report.errors, status: ActiveStatus.configuration.error
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,3 @@
1
+ ActiveStatus::Engine.routes.draw do
2
+ root to: 'application#status'
3
+ end
@@ -0,0 +1,20 @@
1
+ require 'active_status/error'
2
+ require 'active_status/engine'
3
+ require 'active_status/report'
4
+ require 'active_status/configuration'
5
+
6
+ module ActiveStatus
7
+ class << self
8
+ attr_accessor :configuration
9
+ end
10
+
11
+ def self.configure
12
+ self.configuration ||= Configuration.new
13
+
14
+ yield configuration
15
+ end
16
+
17
+ def self.reconfigure
18
+ self.configuration = Configuration.new
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ module ActiveStatus
2
+ class Configuration
3
+ attr_accessor :checks, :error, :success, :verbose
4
+
5
+ def initialize
6
+ self.checks = []
7
+ self.error = 503
8
+ self.success = 200
9
+ self.verbose = false
10
+ end
11
+
12
+ def check(name, &block)
13
+ checks << name
14
+
15
+ Report.define_check(name, block)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module ActiveStatus
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace ActiveStatus
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ module ActiveStatus
2
+ class Error
3
+ attr_accessor :name, :error, :message
4
+
5
+ def initialize(name, error, message)
6
+ self.name = name
7
+ self.error = error.name
8
+ self.message = message&.squish
9
+ end
10
+
11
+ def as_json(_ = nil)
12
+ hash = { name: name, error: error }
13
+ return hash unless ActiveStatus.configuration.verbose
14
+
15
+ hash.merge({ message: message })
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ module ActiveStatus
2
+ class Report
3
+ attr_reader :errors
4
+
5
+ def initialize
6
+ @errors = []
7
+ end
8
+
9
+ def self.define_check(name, body)
10
+ define_method(name, body)
11
+ end
12
+
13
+ def build
14
+ ActiveStatus.configuration.checks.each do |check|
15
+ begin
16
+ send(check)
17
+ rescue StandardError => e
18
+ @errors << Error.new(check, e.class, e.message)
19
+ end
20
+ end
21
+ end
22
+
23
+ def success?
24
+ @errors.empty?
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveStatus
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,19 @@
1
+ module ActiveStatus
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc 'Creates ActiveStatus initializer and add route for your application'
5
+
6
+ def self.default_generator_root
7
+ __dir__
8
+ end
9
+
10
+ def copy_initializer
11
+ template 'initializer.rb', 'config/initializers/active_status_config.rb'
12
+ end
13
+
14
+ def add_route
15
+ route "mount ActiveStatus::Engine => '/status'"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ ActiveStatus.configure do |config|
2
+ # config.success = 200
3
+ # config.error = 503
4
+ # config.verbose = false
5
+
6
+ # Example for checking database connection
7
+ #
8
+ # config.check :database do
9
+ # ActiveRecord::Base.connection.execute('select 1')
10
+ # end
11
+ end
metadata ADDED
@@ -0,0 +1,220 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_status
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Muhammad Usman
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-10-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.17.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.17.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 13.0.1
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '13.0'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 13.0.1
75
+ - !ruby/object:Gem::Dependency
76
+ name: sqlite3
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '1.4'
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 1.4.2
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '1.4'
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: 1.4.2
95
+ - !ruby/object:Gem::Dependency
96
+ name: rspec-rails
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '4.0'
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 4.0.1
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '4.0'
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: 4.0.1
115
+ - !ruby/object:Gem::Dependency
116
+ name: rubocop-rails
117
+ requirement: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '2.8'
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 2.8.1
125
+ type: :development
126
+ prerelease: false
127
+ version_requirements: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.8'
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: 2.8.1
135
+ - !ruby/object:Gem::Dependency
136
+ name: rubocop-rspec
137
+ requirement: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: '1.44'
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 1.44.1
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '1.44'
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: 1.44.1
155
+ - !ruby/object:Gem::Dependency
156
+ name: rubocop-performance
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - "~>"
160
+ - !ruby/object:Gem::Version
161
+ version: '1.8'
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: 1.8.1
165
+ type: :development
166
+ prerelease: false
167
+ version_requirements: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - "~>"
170
+ - !ruby/object:Gem::Version
171
+ version: '1.8'
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: 1.8.1
175
+ description: Description of RailsStatusCheck.
176
+ email:
177
+ - uxman.sherwani@gmail.com
178
+ executables: []
179
+ extensions: []
180
+ extra_rdoc_files:
181
+ - README.md
182
+ files:
183
+ - README.md
184
+ - app/controllers/active_status/application_controller.rb
185
+ - config/routes.rb
186
+ - lib/active_status.rb
187
+ - lib/active_status/configuration.rb
188
+ - lib/active_status/engine.rb
189
+ - lib/active_status/error.rb
190
+ - lib/active_status/report.rb
191
+ - lib/active_status/version.rb
192
+ - lib/generators/active_status/install_generator.rb
193
+ - lib/generators/active_status/templates/initializer.rb
194
+ homepage: https://github.com/uxxman/active_status
195
+ licenses:
196
+ - MIT
197
+ metadata:
198
+ homepage_uri: https://github.com/uxxman/active_status
199
+ source_code_uri: https://github.com/uxxman/active_status
200
+ changelog_uri: https://github.com/uxxman/active_status/releases
201
+ post_install_message:
202
+ rdoc_options: []
203
+ require_paths:
204
+ - lib
205
+ required_ruby_version: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: 2.4.0
210
+ required_rubygems_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '0'
215
+ requirements: []
216
+ rubygems_version: 3.1.2
217
+ signing_key:
218
+ specification_version: 4
219
+ summary: Summary of RailsStatusCheck.
220
+ test_files: []