Skip to content

Commit

Permalink
Ruby 3 support (#615)
Browse files Browse the repository at this point in the history
* Remove warning: instance variable @json_output not initialized

* Ruby 3 support.

More specific for method_missing: Keyword arguments are separated from other argument
https://www.ruby-lang.org/en/news/2020/12/25/ruby-3-0-0-released/

* Need to remove the original one, duh.

* Remove trailing whitespace

* Use normalcase for variable numbers.

* Prefer single-quoted strings when you don't need string interpolation or special symbols.

* Do not use parentheses for method calls with no arguments

* Refactored out use of `eval`.

* Add empty line after guard clause

* As suggested, use Gem::Version to compare Ruby version numbers.
  • Loading branch information
atog authored May 17, 2021
1 parent a33e2db commit 6fc4203
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
17 changes: 12 additions & 5 deletions lib/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,18 @@ def self.client(options = {})
Gitlab::Client.new(options)
end

# Delegate to Gitlab::Client
def self.method_missing(method, *args, &block)
return super unless client.respond_to?(method)

client.send(method, *args, &block)
if Gem::Version.new(RUBY_VERSION).release >= Gem::Version.new('3.0.0')
def self.method_missing(method, *args, **keywargs, &block)
return super unless client.respond_to?(method)

client.send(method, *args, **keywargs, &block)
end
else
def self.method_missing(method, *args, &block)
return super unless client.respond_to?(method)

client.send(method, *args, &block)
end
end

# Delegate to Gitlab::Client
Expand Down
2 changes: 1 addition & 1 deletion lib/gitlab/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def self.run(cmd, args = [])
# Helper method that checks whether we want to get the output as json
# @return [nil]
def self.render_output(cmd, args, data)
if @json_output
if defined?(@json_output) && @json_output
output_json(cmd, args, data)
else
output_table(cmd, args, data)
Expand Down
10 changes: 5 additions & 5 deletions lib/gitlab/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ def namespace(cmd)
# Massage output from 'ri'.
def change_help_output!(cmd, output_str)
output_str = +output_str
output_str.gsub!(/#{cmd}\((.*?)\)/m, "#{cmd} \1")
output_str.gsub!(/,\s*/, ' ')
output_str.gsub!(/#{cmd}(\(.*?\))/m, "#{cmd}\\1")
output_str.gsub!(/,\s*/, ', ')

# Ensure @option descriptions are on a single line
output_str.gsub!(/\n\[/, " \[")
output_str.gsub!(/\s(@)/, "\n@")
output_str.gsub!(/(\])\n(:)/, '\1 \2')
output_str.gsub!(/(:.*)(\n)(.*\.)/, '\1 \3')
output_str.gsub!(/\{(.+)\}/, '"{\1}"')
output_str.gsub!(/(\])\n(:)/, '\\1 \\2')
output_str.gsub!(/(:.*)(\n)(.*\.)/, '\\1 \\3')
output_str.gsub!(/\{(.+)\}/, '"{\\1}"')
end
end
end
2 changes: 1 addition & 1 deletion spec/gitlab/client/build_variables_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

describe '.create_variable' do
before do
stub_post('/projects/3/variables', 'variable')
stub_post('/projects/3/variables', 'variable', { masked: true })
@variable = Gitlab.create_variable(3, 'NEW_VARIABLE', 'new value')
end

Expand Down
4 changes: 2 additions & 2 deletions spec/gitlab/client/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@
describe 'create' do
before do
stub_post('/users/2/impersonation_tokens', 'impersonation_create')
@token = Gitlab.create_user_impersonation_token(2, 'mytoken', scopes)
@token = Gitlab.create_user_impersonation_token(2, 'mytoken', ['api'])
end

it 'gets the correct resource' do
Expand All @@ -614,7 +614,7 @@

it 'removes a token' do
expect(a_delete('/users/2/impersonation_tokens/2')).to have_been_made
expect(@token).to be_empty
expect(@token.to_hash).to be_empty
end
end
end

0 comments on commit 6fc4203

Please sign in to comment.