@@ -96,26 +96,81 @@ def self.configure
9696
9797 @config
9898 end
99+
100+ ##
101+ # Initialize toplevel configuration
102+ # @private
103+ #
104+ def self . init_configuration
105+ configure do |config |
106+ default_project = Google ::Cloud ::Config . deferred do
107+ ENV [ "GOOGLE_CLOUD_PROJECT" ] || ENV [ "GCLOUD_PROJECT" ]
108+ end
109+ default_creds = Google ::Cloud ::Config . deferred do
110+ Google ::Cloud ::Config . credentials_from_env \
111+ "GOOGLE_CLOUD_CREDENTIALS" , "GOOGLE_CLOUD_CREDENTIALS_JSON" ,
112+ "GOOGLE_CLOUD_KEYFILE" , "GOOGLE_CLOUD_KEYFILE_JSON" ,
113+ "GCLOUD_KEYFILE" , "GCLOUD_KEYFILE_JSON"
114+ end
115+
116+ config . add_field! :project_id , default_project ,
117+ match : String , allow_nil : true
118+ config . add_alias! :project , :project_id
119+ config . add_field! :credentials , default_creds , match : Object
120+ config . add_alias! :keyfile , :credentials
121+ end
122+ end
123+
124+ # In June, 2018, set supported version to 2.3 and recommended to 2.4.
125+ # Thereafter, follow the MRI support schedule: supported means non-EOL,
126+ # and recommended means in normal (rather than security) maintenance.
127+ # See https://www.ruby-lang.org/en/downloads/branches/
128+
129+ ##
130+ # Minimum "supported" Ruby version (non-EOL)
131+ # @private
132+ #
133+ SUPPORTED_VERSION_THRESHOLD = "2.0" . freeze
134+
135+ ##
136+ # Minimum "recommended" Ruby version (normal maintenance)
137+ # @private
138+ #
139+ RECOMMENDED_VERSION_THRESHOLD = "2.3" . freeze
140+
141+ ##
142+ # Check Ruby version and emit a warning if it is old
143+ # @private
144+ #
145+ def self . warn_on_old_ruby_version \
146+ supported_version : SUPPORTED_VERSION_THRESHOLD ,
147+ recommended_version : RECOMMENDED_VERSION_THRESHOLD
148+ cur_version = Gem ::Version . new RUBY_VERSION
149+ if cur_version < Gem ::Version . new ( supported_version )
150+ warn "WARNING: You are running Ruby #{ cur_version } , which has reached" \
151+ " end-of-life and is no longer supported by Ruby Core."
152+ warn "It is strongly recommended that you upgrade to Ruby" \
153+ " #{ recommended_version } or later."
154+ warn "See https://www.ruby-lang.org/en/downloads/branches/ for more" \
155+ " info on the Ruby maintenance schedule."
156+ elsif cur_version < Gem ::Version . new ( recommended_version )
157+ warn "WARNING: You are running Ruby #{ cur_version } , which is nearing" \
158+ " end-of-life."
159+ warn "Consider upgrading to Ruby #{ recommended_version } or later."
160+ warn "See https://www.ruby-lang.org/en/downloads/branches/ for more" \
161+ " info on the Ruby maintenance schedule."
162+ end
163+ rescue ArgumentError
164+ warn "Unable to determine current Ruby version."
165+ end
99166 end
100167end
101168
102169# Set the default top-level configuration
103- Google ::Cloud . configure do |config |
104- default_project = Google ::Cloud ::Config . deferred do
105- ENV [ "GOOGLE_CLOUD_PROJECT" ] || ENV [ "GCLOUD_PROJECT" ]
106- end
107- default_creds = Google ::Cloud ::Config . deferred do
108- Google ::Cloud ::Config . credentials_from_env \
109- "GOOGLE_CLOUD_CREDENTIALS" , "GOOGLE_CLOUD_CREDENTIALS_JSON" ,
110- "GOOGLE_CLOUD_KEYFILE" , "GOOGLE_CLOUD_KEYFILE_JSON" ,
111- "GCLOUD_KEYFILE" , "GCLOUD_KEYFILE_JSON"
112- end
170+ Google ::Cloud . init_configuration
113171
114- config . add_field! :project_id , default_project , match : String , allow_nil : true
115- config . add_alias! :project , :project_id
116- config . add_field! :credentials , default_creds , match : Object
117- config . add_alias! :keyfile , :credentials
118- end
172+ # Emit a warning if current Ruby is at or nearing end-of-life
173+ Google ::Cloud . warn_on_old_ruby_version
119174
120175# Auto-load all Google Cloud service gems.
121176Gem . find_files ( "google-cloud-*.rb" ) . each do |google_cloud_service |
0 commit comments