rack-ok 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: 186f17bd5884836db3154ad685eb15daeb1ba76c2ffc79b387c99ca6b98a6883
4
+ data.tar.gz: 5b5cde7d8f1017d14eab7d1fea9c122929bf6c8bfdb14b4eba03e28e53f768fe
5
+ SHA512:
6
+ metadata.gz: 25073bc85b845eced7291a4964c79029659737650f7aa1a6eb84c63cd6d2076e2487e3ec9cba7ba6b3d2310a7f8b146aa5e5df9dc04fd44b8ead99ba3e26be86
7
+ data.tar.gz: 240bdfd4ae10450fa4d4ae131637e760f55ac3f7ece37daeeea0e22938a5fbc87c8a35cd07aec198fa10641a9e8c8ef73c12b4a9db7bc7f313308198f0c7af3f
@@ -0,0 +1,18 @@
1
+ on:
2
+ pull_request:
3
+ push:
4
+ branches:
5
+ - master
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-18.04
9
+ steps:
10
+ - uses: actions/checkout@v2
11
+ - uses: actions/setup-ruby@v1
12
+ with:
13
+ ruby-version: '2.7.2'
14
+ - run: bundle install --jobs=$(($(nproc) - 1)) --retry=3
15
+ - run: bundle exec rubocop --color --parallel
16
+ - run: bundle exec rspec --force-color
17
+
18
+
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ Metrics:
2
+ Enabled: false
3
+
4
+ Style/Documentation:
5
+ Enabled: false
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.1
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,14 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## 0.1.0
11
+
12
+ ### Added
13
+
14
+ - Add Rack::Ok.
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in rack-ok.gemspec
6
+ gemspec
7
+
8
+ gem 'rack-test'
9
+ gem 'rake', '~> 12.0'
10
+ gem 'rspec', '~> 3.0'
11
+ gem 'rubocop'
@@ -0,0 +1,59 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rack-ok (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.1)
10
+ diff-lcs (1.4.4)
11
+ parallel (1.19.2)
12
+ parser (2.7.2.0)
13
+ ast (~> 2.4.1)
14
+ rack (2.2.3)
15
+ rack-test (1.1.0)
16
+ rack (>= 1.0, < 3)
17
+ rainbow (3.0.0)
18
+ rake (12.3.3)
19
+ regexp_parser (1.8.2)
20
+ rexml (3.2.4)
21
+ rspec (3.9.0)
22
+ rspec-core (~> 3.9.0)
23
+ rspec-expectations (~> 3.9.0)
24
+ rspec-mocks (~> 3.9.0)
25
+ rspec-core (3.9.3)
26
+ rspec-support (~> 3.9.3)
27
+ rspec-expectations (3.9.3)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.9.0)
30
+ rspec-mocks (3.9.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.9.0)
33
+ rspec-support (3.9.4)
34
+ rubocop (1.0.0)
35
+ parallel (~> 1.10)
36
+ parser (>= 2.7.1.5)
37
+ rainbow (>= 2.2.2, < 4.0)
38
+ regexp_parser (>= 1.8)
39
+ rexml
40
+ rubocop-ast (>= 0.6.0)
41
+ ruby-progressbar (~> 1.7)
42
+ unicode-display_width (>= 1.4.0, < 2.0)
43
+ rubocop-ast (1.1.0)
44
+ parser (>= 2.7.1.5)
45
+ ruby-progressbar (1.10.1)
46
+ unicode-display_width (1.7.0)
47
+
48
+ PLATFORMS
49
+ ruby
50
+
51
+ DEPENDENCIES
52
+ rack-ok!
53
+ rack-test
54
+ rake (~> 12.0)
55
+ rspec (~> 3.0)
56
+ rubocop
57
+
58
+ BUNDLED WITH
59
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Ryo Nakamura
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,87 @@
1
+ # Rack::Ok
2
+
3
+ [![](https://github.com/r7kamura/rack-ok/workflows/.github/workflows/test.yml/badge.svg)](https://github.com/r7kamura/rack-ok/actions?query=workflow%3A.github%2Fworkflows%2Ftest.yml)
4
+
5
+ Rack middleware to return OK.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rack-ok'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ ```sh
18
+ bundle install
19
+ ```
20
+
21
+ Or install it yourself as:
22
+
23
+ ```sh
24
+ gem install rack-ok
25
+ ```
26
+
27
+ ## Usage
28
+
29
+ Insert `Rack::Ok` to your rack middleware, and the app will respond to `GET /health` with 200 OK.
30
+
31
+ ### For Rails
32
+
33
+ Insert this before at least ActionDispatch::SSL (enabled by config.force_ssl) to prevent request from being redirected.
34
+
35
+ ```ruby
36
+ # config/initializers/ok.rb
37
+ Rails.configuration.middleware.insert(0, Rack::Ok)
38
+ ```
39
+
40
+ ### For Rack
41
+
42
+ ```ruby
43
+ # config.ru
44
+ require 'rack/ok'
45
+ use Rack::Ok
46
+ ```
47
+
48
+ ### Customization
49
+
50
+ Supports these options:
51
+
52
+ - `:body` (default: `"OK"`)
53
+ - `:path` (default: `"/health"`)
54
+
55
+ ```ruby
56
+ use(
57
+ Rack::Ok,
58
+ body: 'Custom response body',
59
+ path: '/custom_ok_path',
60
+ )
61
+ ```
62
+
63
+ ## Development
64
+
65
+ ### Setup
66
+
67
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
68
+
69
+ ### Local installation
70
+
71
+ To install this gem onto your local machine, run `bundle exec rake install`.
72
+
73
+ ### Release
74
+
75
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/r7kamura/rack-ok.
80
+
81
+ ## Acknowledgements
82
+
83
+ This gem is heavily inspired by [rack-health](https://github.com/mirakui/rack-health).
84
+
85
+ ## License
86
+
87
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'rack/ok'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rack/ok/version'
4
+
5
+ module Rack
6
+ class Ok
7
+ DEFAULT_REQUEST_PATH = '/health'
8
+
9
+ DEFAULT_RESPONSE_BODY = 'OK'
10
+
11
+ # @param [#call] app
12
+ # @param [String] body
13
+ # @param [String] path
14
+ def initialize(
15
+ app,
16
+ body: DEFAULT_RESPONSE_BODY,
17
+ path: DEFAULT_REQUEST_PATH
18
+ )
19
+ @app = app
20
+ @body = body
21
+ @path = path
22
+ end
23
+
24
+ # @param [Hash] env Rack env.
25
+ # @return [Array] Rack response.
26
+ def call(env)
27
+ if env['PATH_INFO'] == @path
28
+ [
29
+ '200',
30
+ {
31
+ 'Content-Length' => @body.bytesize.to_s,
32
+ 'Content-Type' => 'text/plain'
33
+ },
34
+ [@body]
35
+ ]
36
+ else
37
+ @app.call(env)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rack
4
+ class Ok
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/rack/ok/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rack-ok'
7
+ spec.version = Rack::Ok::VERSION
8
+ spec.authors = ['Ryo Nakamura']
9
+ spec.email = ['r7kamura@gmail.com']
10
+
11
+ spec.summary = 'Rack middleware to return OK.'
12
+ spec.homepage = 'https://github.com/r7kamura/rack-ok'
13
+ spec.license = 'MIT'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
15
+
16
+ spec.metadata['homepage_uri'] = spec.homepage
17
+ spec.metadata['source_code_uri'] = spec.homepage
18
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/master/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.require_paths = ['lib']
26
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-ok
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ryo Nakamura
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-10-29 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - r7kamura@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".github/workflows/test.yml"
21
+ - ".gitignore"
22
+ - ".rspec"
23
+ - ".rubocop.yml"
24
+ - ".travis.yml"
25
+ - CHANGELOG.md
26
+ - Gemfile
27
+ - Gemfile.lock
28
+ - LICENSE.txt
29
+ - README.md
30
+ - Rakefile
31
+ - bin/console
32
+ - bin/setup
33
+ - lib/rack/ok.rb
34
+ - lib/rack/ok/version.rb
35
+ - rack-ok.gemspec
36
+ homepage: https://github.com/r7kamura/rack-ok
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ homepage_uri: https://github.com/r7kamura/rack-ok
41
+ source_code_uri: https://github.com/r7kamura/rack-ok
42
+ changelog_uri: https://github.com/r7kamura/rack-ok/blob/master/CHANGELOG.md
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: 2.4.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.1.2
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Rack middleware to return OK.
62
+ test_files: []