Skip to content

Commit

Permalink
warn on EOL ruby version (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRoyalTnetennba authored Aug 29, 2018
1 parent 2692df7 commit 9cb1eab
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 0.9.0 (2018-08-16)
## 0.9.1 (2018-08-29)
* Warn on EOL ruby versions.
* Fix DateTime normalization.

## 0.9.0 (2018-08-20)
* Add RemoteServerError class for 5xx level errors.
* Allow to_json to be called with arguments
* Expires_in now sets and reflects current expires_at value
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,12 @@ client.fetch_access_token!
`gem install signet`

Be sure `https://rubygems.org` is in your gem sources.

## Supported Ruby Versions
This library is currently supported on Ruby 1.9+.
However, Ruby 2.4 or later is strongly recommended, as earlier releases have
reached or are nearing end-of-life. After March 31, 2019, Google will provide
official support only for Ruby versions that are considered current and
supported by Ruby Core (that is, Ruby versions that are either in normal
maintenance or in security maintenance).
See https://www.ruby-lang.org/en/downloads/branches/ for further details.
63 changes: 62 additions & 1 deletion lib/signet/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,71 @@ module Signet
module VERSION
MAJOR = 0
MINOR = 9
TINY = 0
TINY = 1
PRE = nil

STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')

# On March 31, 2019, set supported version to 2.4 and recommended to 2.6.
# Thereafter, follow the MRI support schedule: supported means non-EOL,
# and recommended means in normal (rather than security) maintenance.
# See https://www.ruby-lang.org/en/downloads/branches/
##
# Minimum "supported" Ruby version (non-EOL)
# @private
#
SUPPORTED_VERSION_THRESHOLD = '1.9'.freeze
##
# Minimum "recommended" Ruby version (normal maintenance)
# @private
#
RECOMMENDED_VERSION_THRESHOLD = '2.4'.freeze
##
# Check Ruby version and emit a warning if it is old
# @private
#
def self.warn_on_old_ruby_version
return if ENV['GOOGLE_CLOUD_SUPPRESS_RUBY_WARNINGS']
cur_version = Gem::Version.new RUBY_VERSION
if cur_version < Gem::Version.new(SUPPORTED_VERSION_THRESHOLD)
warn_unsupported_ruby cur_version, RECOMMENDED_VERSION_THRESHOLD
elsif cur_version < Gem::Version.new(RECOMMENDED_VERSION_THRESHOLD)
warn_nonrecommended_ruby cur_version, RECOMMENDED_VERSION_THRESHOLD
end
rescue ArgumentError
'Unable to determine current Ruby version.'
end

##
# Print a warning for an EOL version of Ruby
# @private
#
def self.warn_unsupported_ruby cur_version, recommended_version
"WARNING: You are running Ruby #{cur_version}, which has reached" +
" end-of-life and is no longer supported by Ruby Core.\n" +
'Signet works best on supported versions of' +
' Ruby. It is strongly recommended that you upgrade to Ruby' +
" #{recommended_version} or later. \n" +
'See https://www.ruby-lang.org/en/downloads/branches/ for more' +
" info on the Ruby maintenance schedule.\n" +
'To suppress this message, set the' +
' GOOGLE_CLOUD_SUPPRESS_RUBY_WARNINGS environment variable.'
end

##
# Print a warning for a supported but nearing EOL version of Ruby
# @private
#
def self.warn_nonrecommended_ruby cur_version, recommended_version
"WARNING: You are running Ruby #{cur_version}, which is nearing" +
" end-of-life.\n" +
'Signet works best on supported versions of' +
" Ruby. Consider upgrading to Ruby #{recommended_version} or later.\n" +
'See https://www.ruby-lang.org/en/downloads/branches/ for more' +
" info on the Ruby maintenance schedule.\n" +
'To suppress this message, set the' +
' GOOGLE_CLOUD_SUPPRESS_RUBY_WARNINGS environment variable.'
end
end
end
end
2 changes: 2 additions & 0 deletions signet.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ Gem::Specification.new do |s|
s.add_development_dependency 'launchy', '~> 2.4'
s.add_development_dependency 'kramdown', '~> 1.5'
s.add_development_dependency 'simplecov', '~> 0.9'

s.post_install_message = Signet::VERSION::warn_on_old_ruby_version
end

0 comments on commit 9cb1eab

Please sign in to comment.