From c87c7cc416a6202edc7ec398f5cae1b9d6ee5ac5 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Fri, 1 Mar 2024 19:07:57 +0100 Subject: [PATCH] Don't emit Ruby warnings when requiring `opensearch-dsl` Previous output: ``` $ RUBYOPT=-w bundle exec irb irb(main):001> require "opensearch-dsl" opensearch-ruby/lib/opensearch/dsl/search/options.rb:59: warning: method redefined; discarding old fields opensearch-ruby/lib/opensearch/dsl/search/options.rb:55: warning: previous definition of fields was here opensearch-ruby/lib/opensearch/dsl/search/options.rb:59: warning: method redefined; discarding old script_fields opensearch-ruby/lib/opensearch/dsl/search/options.rb:55: warning: previous definition of script_fields was here opensearch-ruby/lib/opensearch/dsl/search/options.rb:59: warning: method redefined; discarding old fielddata_fields opensearch-ruby/lib/opensearch/dsl/search/options.rb:55: warning: previous definition of fielddata_fields was here opensearch-ruby/lib/opensearch/dsl/search/options.rb:59: warning: method redefined; discarding old rescore opensearch-ruby/lib/opensearch/dsl/search/options.rb:55: warning: previous definition of rescore was here opensearch-ruby/lib/opensearch/dsl/search/options.rb:59: warning: method redefined; discarding old explain opensearch-ruby/lib/opensearch/dsl/search/options.rb:55: warning: previous definition of explain was here opensearch-ruby/lib/opensearch/dsl/search/options.rb:59: warning: method redefined; discarding old version opensearch-ruby/lib/opensearch/dsl/search/options.rb:55: warning: previous definition of version was here opensearch-ruby/lib/opensearch/dsl/search/options.rb:59: warning: method redefined; discarding old indices_boost opensearch-ruby/lib/opensearch/dsl/search/options.rb:55: warning: previous definition of indices_boost was here opensearch-ruby/lib/opensearch/dsl/search/options.rb:59: warning: method redefined; discarding old track_scores opensearch-ruby/lib/opensearch/dsl/search/options.rb:55: warning: previous definition of track_scores was here opensearch-ruby/lib/opensearch/dsl/search/options.rb:59: warning: method redefined; discarding old min_score opensearch-ruby/lib/opensearch/dsl/search/options.rb:55: warning: previous definition of min_score was here opensearch-ruby/lib/opensearch/dsl/search/options.rb:59: warning: method redefined; discarding old track_total_hits opensearch-ruby/lib/opensearch/dsl/search/options.rb:55: warning: previous definition of track_total_hits was here opensearch-ruby/lib/opensearch/dsl/search/base_component.rb:75: warning: method redefined; discarding old max_expansions opensearch-ruby/lib/opensearch/dsl/search/base_component.rb:75: warning: previous definition of max_expansions was here => true ``` Signed-off-by: Earlopain <14981592+Earlopain@users.noreply.github.com> --- CHANGELOG.md | 1 + lib/opensearch/dsl/search/options.rb | 6 +++--- lib/opensearch/dsl/search/queries/match.rb | 1 - 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84a8a2c8a..9f6b3f045 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Deprecated ### Removed ### Fixed +- Don't emit Ruby warnings when requiring `opensearch-dsl` ([#231](https://github.com/opensearch-project/opensearch-ruby/issues/231)) ### Security ## [3.2.0] diff --git a/lib/opensearch/dsl/search/options.rb b/lib/opensearch/dsl/search/options.rb index 2408a486e..ec3e0652c 100644 --- a/lib/opensearch/dsl/search/options.rb +++ b/lib/opensearch/dsl/search/options.rb @@ -55,10 +55,10 @@ def initialize(*_args) define_method name do |*args| @hash[name] = args.pop end + end - define_method name.to_s.gsub(/^_(.*)/, '\1') do |*args| - @hash[name] = args.pop - end + def source(*args) + @hash[:_source] = args.pop end # Returns true when there are no search options defined diff --git a/lib/opensearch/dsl/search/queries/match.rb b/lib/opensearch/dsl/search/queries/match.rb index c3de780b7..56f4da6dd 100644 --- a/lib/opensearch/dsl/search/queries/match.rb +++ b/lib/opensearch/dsl/search/queries/match.rb @@ -59,7 +59,6 @@ class Match option_method :lenient option_method :zero_terms_query option_method :cutoff_frequency - option_method :max_expansions end end end