Skip to content

Commit

Permalink
Avoid method redefinition warnings in verbose warning mode
Browse files Browse the repository at this point in the history
Use alias hack to avoid most of the warnings.

Silence warnings in mail, hanna-nouveau, and minjs gems in the
spec_w rake task.
  • Loading branch information
jeremyevans committed Dec 3, 2020
1 parent e7e4542 commit 4aa2289
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
= master

* Avoid method redefinition warnings in verbose warning mode (jeremyevans)

* Make typecast_params.convert! handle explicit nil values the same as missing values (jeremyevans)

= 3.38.0 (2020-11-16)
Expand Down
5 changes: 5 additions & 0 deletions lib/roda.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def define_roda_method(meth, expected_arity, &block)
alias_method meth, temp_method
undef_method temp_method
private meth
alias_method meth, meth
meth = :"#{meth}_arity"
elsif required_args > 1
b = block
Expand Down Expand Up @@ -144,6 +145,7 @@ def define_roda_method(meth, expected_arity, &block)

define_method(meth, &block)
private meth
alias_method meth, meth

if arity_meth
required_args, optional_args, rest, keyword = _define_roda_method_arg_numbers(instance_method(meth))
Expand All @@ -167,6 +169,7 @@ def define_roda_method(meth, expected_arity, &block)
send(meth, *a)
end
private arity_meth
alias_method arity_meth, arity_meth
end

call_meth
Expand Down Expand Up @@ -199,6 +202,7 @@ def freeze

private

alias set_default_headers set_default_headers
def set_default_headers
@headers['Content-Type'] ||= 'text/html'
end
Expand Down Expand Up @@ -403,6 +407,7 @@ def def_roda_before
class_eval("def _roda_before; #{meths.join(';')} end", __FILE__, __LINE__)
end
private :_roda_before
alias_method :_roda_before, :_roda_before
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/roda/plugins/default_headers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def self.configure(app, headers={})
response_class.class_eval(<<-END, __FILE__, __LINE__+1)
private
alias set_default_headers set_default_headers
def set_default_headers
h = @headers
#{headers.map{|k,v| "h[#{k.inspect}] ||= #{v.inspect}"}.join('; ')}
Expand Down
2 changes: 2 additions & 0 deletions lib/roda/plugins/mail_processor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,8 @@ def match_#{field}(address)

undef_method :match_rcpt
undef_method :match_text
undef_method :match_body
undef_method :match_subject

# Same as +header+, but also mark the message as being handled.
def handle_header(key, value=nil)
Expand Down
1 change: 1 addition & 0 deletions lib/roda/plugins/type_routing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ def self.configure(app, opts = {})
app::RodaRequest.send(:define_method, type) do |&block|
on_type(type, &block)
end
app::RodaRequest.send(:alias_method, type, type)
end

app.opts[:type_routing] = config.freeze
Expand Down
3 changes: 2 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

if ENV['WARNING']
require 'warning'
Warning.ignore([:missing_ivar, :method_redefined], File.dirname(File.dirname(__FILE__)))
Warning.ignore(:missing_ivar, File.dirname(File.dirname(__FILE__)))
Warning.ignore(%r{gems/(mail|hanna-nouveau|minjs)-\d})
Warning.dedup if Warning.respond_to?(:dedup)
end

Expand Down

0 comments on commit 4aa2289

Please sign in to comment.