Skip to content

Commit 6c1445a

Browse files
committed
Lint/StructNewOverride
All Ruby Objects have a method named "method" which can be used to retrieve a method by name: irb(main):002> "".method(:length) => #<Method: String#length()> Our request struct accidentally overrides "method" and its version returns the name of the HTTP method, e.g. GET. This breaks the contract if any caller were to call request.method and expect the Object behavior. Since Request is public API, renaming "method" to something else would be a breaking change.
1 parent f590f40 commit 6c1445a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,6 @@ Lint/RescueException:
618618
- 'lib/puppet/util/command_line/trollop.rb'
619619
- 'util/rspec_grouper'
620620

621-
Lint/StructNewOverride:
622-
Exclude:
623-
- 'lib/puppet/network/http/request.rb'
624-
625621
# Configuration parameters: AllowComments, AllowNil.
626622
Lint/SuppressedException:
627623
Exclude:

lib/puppet/network/http/request.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# frozen_string_literal: true
2-
Puppet::Network::HTTP::Request = Struct.new(:headers, :params, :method, :path, :routing_path, :client_cert, :body) do
2+
3+
# This class is effectively public API, because a Request object is passed as a
4+
# parameter to the current Handler subclass. Puppetserver implements its own
5+
# Handler
6+
# https://github.com/puppetlabs/puppetserver/blob/8.3.0/src/ruby/puppetserver-lib/puppet/server/network/http/handler.rb#L9
7+
# and the Request object is passed to its Handler#body method
8+
# https://github.com/puppetlabs/puppetserver/blob/8.3.0/src/ruby/puppetserver-lib/puppet/server/network/http/handler.rb#L36
9+
Puppet::Network::HTTP::Request = Struct.new(:headers, :params, :method, :path, :routing_path, :client_cert, :body) do # rubocop:disable Lint/StructNewOverride
310
def self.from_hash(hash)
411
symbol_members = members.collect(&:intern)
512
unknown = hash.keys - symbol_members

0 commit comments

Comments
 (0)