diff --git a/.document b/.document new file mode 100644 index 0000000..5035202 --- /dev/null +++ b/.document @@ -0,0 +1,3 @@ +LICENSE.txt +README.md +lib/ diff --git a/.github/workflows/push_gem.yml b/.github/workflows/push_gem.yml new file mode 100644 index 0000000..6e453aa --- /dev/null +++ b/.github/workflows/push_gem.yml @@ -0,0 +1,46 @@ +name: Publish gem to rubygems.org + +on: + push: + tags: + - 'v*' + +permissions: + contents: read + +jobs: + push: + if: github.repository == 'ruby/timeout' + runs-on: ubuntu-latest + + environment: + name: rubygems.org + url: https://rubygems.org/gems/timeout + + permissions: + contents: write + id-token: write + + steps: + - name: Harden Runner + uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1 + with: + egress-policy: audit + + - uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 + + - name: Set up Ruby + uses: ruby/setup-ruby@a6e6f86333f0a2523ece813039b8b4be04560854 # v1.190.0 + with: + bundler-cache: true + ruby-version: ruby + + - name: Publish to RubyGems + uses: rubygems/release-gem@612653d273a73bdae1df8453e090060bb4db5f31 # v1 + + - name: Create GitHub release + run: | + tag_name="$(git describe --tags --abbrev=0)" + gh release create "${tag_name}" --verify-tag --generate-notes + env: + GITHUB_TOKEN: ${{ secrets.MATZBOT_GITHUB_WORKFLOW_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e29634b..23f46cf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,8 @@ jobs: exclude: - os: macos-latest ruby: truffleruby + - os: ubuntu-latest + ruby: truffleruby-head runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 diff --git a/LICENSE.txt b/BSDL similarity index 83% rename from LICENSE.txt rename to BSDL index a009cae..66d9359 100644 --- a/LICENSE.txt +++ b/BSDL @@ -4,10 +4,10 @@ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. + notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..48e5a96 --- /dev/null +++ b/COPYING @@ -0,0 +1,56 @@ +Ruby is copyrighted free software by Yukihiro Matsumoto . +You can redistribute it and/or modify it under either the terms of the +2-clause BSDL (see the file BSDL), or the conditions below: + +1. You may make and give away verbatim copies of the source form of the + software without restriction, provided that you duplicate all of the + original copyright notices and associated disclaimers. + +2. You may modify your copy of the software in any way, provided that + you do at least ONE of the following: + + a. place your modifications in the Public Domain or otherwise + make them Freely Available, such as by posting said + modifications to Usenet or an equivalent medium, or by allowing + the author to include your modifications in the software. + + b. use the modified software only within your corporation or + organization. + + c. give non-standard binaries non-standard names, with + instructions on where to get the original software distribution. + + d. make other distribution arrangements with the author. + +3. You may distribute the software in object code or binary form, + provided that you do at least ONE of the following: + + a. distribute the binaries and library files of the software, + together with instructions (in the manual page or equivalent) + on where to get the original distribution. + + b. accompany the distribution with the machine-readable source of + the software. + + c. give non-standard binaries non-standard names, with + instructions on where to get the original software distribution. + + d. make other distribution arrangements with the author. + +4. You may modify and include the part of the software into any other + software (possibly commercial). But some files in the distribution + are not written by the author, so that they are not under these terms. + + For the list of those files and their copying conditions, see the + file LEGAL. + +5. The scripts and library files supplied as input to or produced as + output from the software do not automatically fall under the + copyright of the software, but belong to whomever generated them, + and may be sold commercially, and may be aggregated with this + software. + +6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + PURPOSE. diff --git a/README.md b/README.md index db1ad0a..61fe2d3 100644 --- a/README.md +++ b/README.md @@ -3,10 +3,6 @@ Timeout provides a way to auto-terminate a potentially long-running operation if it hasn't finished in a fixed amount of time. -Previous versions didn't use a module for namespacing, however -#timeout is provided for backwards compatibility. You -should prefer Timeout.timeout instead. - ## Installation Add this line to your application's Gemfile: @@ -27,7 +23,7 @@ Or install it yourself as: ```ruby require 'timeout' -status = Timeout::timeout(5) { +status = Timeout.timeout(5) { # Something that should be interrupted if it takes more than 5 seconds... } ``` diff --git a/lib/timeout.rb b/lib/timeout.rb index d8806e2..bf12f37 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -4,7 +4,7 @@ # == Synopsis # # require 'timeout' -# status = Timeout::timeout(5) { +# status = Timeout.timeout(5) { # # Something that should be interrupted if it takes more than 5 seconds... # } # @@ -13,28 +13,25 @@ # Timeout provides a way to auto-terminate a potentially long-running # operation if it hasn't finished in a fixed amount of time. # -# Previous versions didn't use a module for namespacing, however -# #timeout is provided for backwards compatibility. You -# should prefer Timeout.timeout instead. -# # == Copyright # # Copyright:: (C) 2000 Network Applied Communication Laboratory, Inc. # Copyright:: (C) 2000 Information-technology Promotion Agency, Japan module Timeout - VERSION = "0.4.1" + # The version + VERSION = "0.4.2" # Internal error raised to when a timeout is triggered. class ExitException < Exception - def exception(*) + def exception(*) # :nodoc: self end end # Raised by Timeout.timeout when the block times out. class Error < RuntimeError - def self.handle_timeout(message) + def self.handle_timeout(message) # :nodoc: exc = ExitException.new(message) begin diff --git a/test/test_timeout.rb b/test/test_timeout.rb index b1a93a7..34966f9 100644 --- a/test/test_timeout.rb +++ b/test/test_timeout.rb @@ -66,7 +66,7 @@ def test_nested_timeout a = nil assert_raise(Timeout::Error) do Timeout.timeout(0.1) { - Timeout.timeout(1) { + Timeout.timeout(30) { nil while true } a = 1 @@ -84,7 +84,7 @@ class MyNewErrorInner < StandardError; end def test_nested_timeout_error_identity begin Timeout.timeout(0.1, MyNewErrorOuter) { - Timeout.timeout(1, MyNewErrorInner) { + Timeout.timeout(30, MyNewErrorInner) { nil while true } } @@ -108,7 +108,7 @@ def test_nested_timeout_which_error_bubbles_up raised_exception = e end - assert_equal 'inner message', e.message + assert_equal 'inner message', raised_exception.message end def test_cannot_convert_into_time_interval diff --git a/timeout.gemspec b/timeout.gemspec index 258517c..5449494 100644 --- a/timeout.gemspec +++ b/timeout.gemspec @@ -20,6 +20,7 @@ Gem::Specification.new do |spec| spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = spec.homepage + spec.metadata["changelog_uri"] = spec.homepage + "/releases" spec.required_ruby_version = '>= 2.6.0'