diff --git a/.bundle/config b/.bundle/config deleted file mode 100644 index 10c4c8f87..000000000 --- a/.bundle/config +++ /dev/null @@ -1,2 +0,0 @@ ---- -BUNDLE_CLEAN: "true" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..3fc56e90c --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,15 @@ +name: Lint +on: [push, pull_request] +jobs: + rubocop: + name: RuboCop + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.5 + bundler-cache: true + - run: bundle exec rubocop diff --git a/.github/workflows/test-unreleased.yml b/.github/workflows/test-unreleased.yml index 42ec82740..a9f76f7ac 100644 --- a/.github/workflows/test-unreleased.yml +++ b/.github/workflows/test-unreleased.yml @@ -24,7 +24,6 @@ jobs: - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.entry.ruby_version }} - - name: Checkout OpenSearch uses: actions/checkout@v3 with: diff --git a/.gitignore b/.gitignore index 0bea8bf2d..be2ace278 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.bundle .config .yardoc _yardoc diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 000000000..756a9d653 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,18 @@ +inherit_from: .rubocop_todo.yml + +require: + - rubocop-rake + - rubocop-rspec + +AllCops: + TargetRubyVersion: 2.5 + NewCops: enable + +RSpec/ImplicitExpect: + Enabled: false + +RSpec/ImplicitSubject: + Enabled: false + +Metrics: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 000000000..a4848e7fd --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,1493 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-04-03 22:03:51 UTC using RuboCop version 1.28.2. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 6 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: TreatCommentsAsGroupSeparators, ConsiderPunctuation, Include. +# Include: **/*.gemspec +Gemspec/OrderedDependencies: + Exclude: + - 'opensearch-transport/opensearch-transport.gemspec' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RequireMFA: + Exclude: + - 'opensearch-transport/opensearch-transport.gemspec' + +# Offense count: 4 +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'opensearch-api/opensearch-api.gemspec' + - 'opensearch-dsl/opensearch-dsl.gemspec' + - 'opensearch-ruby/opensearch-ruby.gemspec' + - 'opensearch-transport/opensearch-transport.gemspec' + +# Offense count: 3 +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RubyVersionGlobalsUsage: + Exclude: + - 'opensearch-dsl/opensearch-dsl.gemspec' + - 'opensearch-transport/opensearch-transport.gemspec' + +# Offense count: 3 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: with_first_argument, with_fixed_indentation +Layout/ArgumentAlignment: + Exclude: + - 'opensearch-transport/test/profile/client_benchmark_test.rb' + - 'profile/benchmarking/measurable.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyleAlignWith, Severity. +# SupportedStylesAlignWith: start_of_line, begin +Layout/BeginEndAlignment: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/http/curb.rb' + +# Offense count: 6 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyleAlignWith. +# SupportedStylesAlignWith: either, start_of_block, start_of_line +Layout/BlockAlignment: + Exclude: + - 'opensearch-transport/spec/opensearch/connections/collection_spec.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +Layout/ClosingHeredocIndentation: + Exclude: + - 'opensearch-transport/test/unit/transport_base_test.rb' + +# Offense count: 36 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: leading, trailing +Layout/DotPosition: + Exclude: + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'opensearch-transport/test/unit/transport_faraday_test.rb' + - 'opensearch-transport/test/unit/transport_manticore_test.rb' + - 'rake_tasks/opensearch_tasks.rake' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +Layout/ElseAlignment: + Exclude: + - 'opensearch-transport/spec/spec_helper.rb' + - 'opensearch-transport/test/test_helper.rb' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +Layout/EmptyLineAfterGuardClause: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/sniffer.rb' + - 'profile/benchmarking/results.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +Layout/EmptyLineAfterMagicComment: + Exclude: + - 'opensearch-transport/opensearch-transport.gemspec' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EmptyLineBetweenMethodDefs, EmptyLineBetweenClassDefs, EmptyLineBetweenModuleDefs, AllowAdjacentOneLineDefs, NumberOfEmptyLines. +Layout/EmptyLineBetweenDefs: + Exclude: + - 'profile/benchmarking/results.rb' + +# Offense count: 3 +# This cop supports safe auto-correction (--auto-correct). +Layout/EmptyLines: + Exclude: + - 'opensearch-transport/test/test_helper.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'profile/benchmarking/results.rb' + +# Offense count: 129 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, no_empty_lines +Layout/EmptyLinesAroundBlockBody: + Exclude: + - 'opensearch-transport/spec/opensearch/connections/collection_spec.rb' + - 'opensearch-transport/spec/opensearch/connections/selector_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/base_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/test/unit/connection_test.rb' + - 'opensearch-transport/test/unit/response_test.rb' + - 'opensearch-transport/test/unit/serializer_test.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'profile/benchmarking/benchmarking_tasks.rake' + +# Offense count: 9 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines, beginning_only, ending_only +Layout/EmptyLinesAroundClassBody: + Exclude: + - 'opensearch-transport/test/integration/transport_test.rb' + - 'opensearch-transport/test/unit/connection_test.rb' + - 'opensearch-transport/test/unit/serializer_test.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'opensearch-transport/test/unit/transport_curb_test.rb' + - 'opensearch-transport/test/unit/transport_faraday_test.rb' + - 'opensearch-transport/test/unit/transport_manticore_test.rb' + - 'profile/benchmarking/results.rb' + +# Offense count: 19 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines +Layout/EmptyLinesAroundModuleBody: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/connections/collection.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/connections/connection.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/connections/selector.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/errors.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/http/curb.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/loggable.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/response.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/serializer/multi_json.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/sniffer.rb' + - 'profile/benchmarking.rb' + - 'profile/benchmarking/complex.rb' + - 'profile/benchmarking/measurable.rb' + - 'profile/benchmarking/results.rb' + - 'profile/benchmarking/simple.rb' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyleAlignWith, Severity. +# SupportedStylesAlignWith: keyword, variable, start_of_line +Layout/EndAlignment: + Exclude: + - 'opensearch-transport/spec/spec_helper.rb' + - 'opensearch-transport/test/test_helper.rb' + +# Offense count: 13 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: AllowForAlignment, AllowBeforeTrailingComments, ForceEqualSignAlignment. +Layout/ExtraSpacing: + Exclude: + - 'opensearch-transport/test/integration/transport_test.rb' + - 'opensearch-transport/test/profile/client_benchmark_test.rb' + - 'opensearch-transport/test/test_helper.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'opensearch-transport/test/unit/transport_faraday_test.rb' + - 'opensearch-transport/test/unit/transport_manticore_test.rb' + - 'profile/benchmarking/simple.rb' + - 'scripts/github_pages_generator.rb' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: consistent, consistent_relative_to_receiver, special_for_inner_method_call, special_for_inner_method_call_in_parentheses +Layout/FirstArgumentIndentation: + Exclude: + - 'opensearch-transport/test/integration/transport_test.rb' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_brackets +Layout/FirstArrayElementIndentation: + Exclude: + - 'profile/benchmarking/results.rb' + +# Offense count: 11 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_braces +Layout/FirstHashElementIndentation: + Exclude: + - 'opensearch-transport/spec/opensearch/transport/base_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/sniffer_spec.rb' + - 'opensearch-transport/test/integration/transport_test.rb' + - 'opensearch-transport/test/unit/transport_faraday_test.rb' + +# Offense count: 22 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. +# SupportedHashRocketStyles: key, separator, table +# SupportedColonStyles: key, separator, table +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +Layout/HashAlignment: + Exclude: + - 'opensearch-transport/spec/opensearch/transport/sniffer_spec.rb' + - 'opensearch-transport/test/profile/client_benchmark_test.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'opensearch-transport/test/unit/transport_faraday_test.rb' + - 'opensearch-transport/test/unit/transport_manticore_test.rb' + - 'profile/benchmarking/measurable.rb' + +# Offense count: 5 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: Width, AllowedPatterns, IgnoredPatterns. +Layout/IndentationWidth: + Exclude: + - 'opensearch-transport/spec/opensearch/connections/collection_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/spec/spec_helper.rb' + - 'opensearch-transport/test/test_helper.rb' + - 'profile/benchmarking/results.rb' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineArrayBraceLayout: + Exclude: + - 'profile/benchmarking/benchmarking_tasks.rake' + +# Offense count: 6 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: symmetrical, new_line, same_line +Layout/MultilineHashBraceLayout: + Exclude: + - 'opensearch-transport/test/integration/transport_test.rb' + - 'opensearch-transport/test/unit/transport_faraday_test.rb' + - 'profile/benchmarking.rb' + - 'profile/benchmarking/results.rb' + +# Offense count: 48 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented, indented_relative_to_receiver +Layout/MultilineMethodCallIndentation: + Exclude: + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'opensearch-transport/test/unit/transport_manticore_test.rb' + - 'rake_tasks/opensearch_tasks.rake' + - 'rake_tasks/update_version.rake' + +# Offense count: 3 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: aligned, indented +Layout/MultilineOperationIndentation: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/connections/connection.rb' + +# Offense count: 11 +# This cop supports safe auto-correction (--auto-correct). +Layout/SpaceAfterComma: + Exclude: + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'profile/benchmarking/complex.rb' + - 'profile/benchmarking/simple.rb' + - 'rake_tasks/docker_tasks.rake' + - 'rake_tasks/test_tasks.rake' + - 'rake_tasks/unified_release_tasks.rake' + - 'rake_tasks/update_version.rake' + +# Offense count: 5 +# This cop supports safe auto-correction (--auto-correct). +Layout/SpaceAfterNot: + Exclude: + - 'opensearch-transport/test/unit/connection_test.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyleInsidePipes. +# SupportedStylesInsidePipes: space, no_space +Layout/SpaceAroundBlockParameters: + Exclude: + - 'rake_tasks/test_tasks.rake' + +# Offense count: 42 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: space, no_space +Layout/SpaceAroundEqualsInParameterDefault: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/connections/collection.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/connections/connection.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/connections/selector.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/http/curb.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/http/faraday.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/http/manticore.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/response.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/serializer/multi_json.rb' + - 'opensearch-transport/spec/opensearch/connections/selector_spec.rb' + - 'opensearch-transport/test/test_helper.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'profile/benchmarking/measurable.rb' + - 'profile/benchmarking/simple.rb' + - 'rake_tasks/opensearch_tasks.rake' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +Layout/SpaceAroundKeyword: + Exclude: + - 'opensearch-transport/test/profile/client_benchmark_test.rb' + +# Offense count: 4 +# This cop supports safe auto-correction (--auto-correct). +Layout/SpaceAroundMethodCallOperator: + Exclude: + - 'opensearch-transport/test/unit/transport_base_test.rb' + +# Offense count: 26 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: AllowForAlignment, EnforcedStyleForExponentOperator. +# SupportedStylesForExponentOperator: space, no_space +Layout/SpaceAroundOperators: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/connections/connection.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/connections/selector.rb' + - 'opensearch-transport/test/profile/client_benchmark_test.rb' + - 'opensearch-transport/test/unit/connection_test.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'profile/benchmarking/complex.rb' + - 'profile/benchmarking/results.rb' + - 'profile/benchmarking/simple.rb' + - 'rake_tasks/opensearch_tasks.rake' + - 'rake_tasks/unified_release_tasks.rake' + - 'rake_tasks/update_version.rake' + - 'scripts/github_pages_generator.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +Layout/SpaceBeforeComma: + Exclude: + - 'opensearch-transport/opensearch-transport.gemspec' + +# Offense count: 99 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBrackets. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBrackets: space, no_space +Layout/SpaceInsideArrayLiteralBrackets: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/sniffer.rb' + - 'opensearch-transport/opensearch-transport.gemspec' + - 'opensearch-transport/spec/opensearch/connections/collection_spec.rb' + - 'opensearch-transport/spec/opensearch/connections/selector_spec.rb' + - 'opensearch-transport/test/integration/transport_test.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'opensearch-transport/test/unit/transport_curb_test.rb' + - 'opensearch-transport/test/unit/transport_faraday_test.rb' + - 'opensearch-transport/test/unit/transport_manticore_test.rb' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. +# SupportedStyles: space, no_space +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideBlockBraces: + Exclude: + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + +# Offense count: 150 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces. +# SupportedStyles: space, no_space, compact +# SupportedStylesForEmptyBraces: space, no_space +Layout/SpaceInsideHashLiteralBraces: + Exclude: + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/test/profile/client_benchmark_test.rb' + - 'opensearch-transport/test/unit/connection_test.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'opensearch-transport/test/unit/transport_curb_test.rb' + - 'opensearch-transport/test/unit/transport_faraday_test.rb' + - 'opensearch-transport/test/unit/transport_manticore_test.rb' + +# Offense count: 12 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: space, compact, no_space +Layout/SpaceInsideParens: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/connections/connection.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/connections/selector.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'opensearch-transport/test/unit/transport_manticore_test.rb' + +# Offense count: 4 +# This cop supports safe auto-correction (--auto-correct). +Layout/SpaceInsidePercentLiteralDelimiters: + Exclude: + - 'opensearch-transport/test/unit/transport_curb_test.rb' + - 'opensearch-transport/test/unit/transport_manticore_test.rb' + +# Offense count: 5 +# Configuration parameters: IgnoredMethods. +Lint/AmbiguousBlockAssociation: + Exclude: + - 'opensearch-dsl/test/integration/search_aggregation_geo_test.rb' + - 'opensearch-dsl/test/integration/search_sort_test.rb' + - 'opensearch-dsl/test/integration/search_suggest_test.rb' + - 'opensearch-dsl/test/integration/search_test.rb' + +# Offense count: 6 +# This cop supports safe auto-correction (--auto-correct). +Lint/AmbiguousOperatorPrecedence: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/connections/connection.rb' + - 'opensearch-transport/test/unit/connection_test.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'profile/benchmarking/results.rb' + - 'rake_tasks/update_version.rake' + +# Offense count: 3 +# This cop supports safe auto-correction (--auto-correct). +Lint/AmbiguousRegexpLiteral: + Exclude: + - 'rake_tasks/update_version.rake' + +# Offense count: 6 +# Configuration parameters: AllowSafeAssignment. +Lint/AssignmentInCondition: + Exclude: + - 'opensearch-api/lib/opensearch/api/utils.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/queries/bool.rb' + - 'opensearch-dsl/test/test_helper.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/sniffer.rb' + - 'opensearch-transport/test/test_helper.rb' + +# Offense count: 18 +# Configuration parameters: AllowedMethods. +# AllowedMethods: enums +Lint/ConstantDefinitionInBlock: + Exclude: + - 'opensearch-dsl/test/unit/dsl_test.rb' + - 'opensearch-dsl/test/unit/search_base_aggregation_component_test.rb' + - 'opensearch-dsl/test/unit/search_base_component_test.rb' + - 'opensearch-dsl/test/unit/search_test.rb' + - 'opensearch-transport/spec/opensearch/connections/selector_spec.rb' + +# Offense count: 1 +# This cop supports unsafe auto-correction (--auto-correct-all). +Lint/DisjunctiveAssignmentInConstructor: + Exclude: + - 'opensearch-dsl/lib/opensearch/dsl/search/sort.rb' + +# Offense count: 1 +# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. +Lint/DuplicateBranch: + Exclude: + - 'opensearch-ruby/lib/opensearch.rb' + +# Offense count: 5 +# Configuration parameters: AllowComments, AllowEmptyLambdas. +Lint/EmptyBlock: + Exclude: + - 'opensearch-dsl/spec/opensearch/dsl/search/aggregations/global_spec.rb' + - 'opensearch-dsl/test/unit/search_test.rb' + +# Offense count: 6 +# This cop supports unsafe auto-correction (--auto-correct-all). +Lint/NonDeterministicRequireOrder: + Exclude: + - 'opensearch-api/lib/opensearch/api.rb' + - 'opensearch-dsl/lib/opensearch/dsl.rb' + +# Offense count: 4 +Lint/RescueException: + Exclude: + - 'opensearch-api/lib/opensearch/api/actions/ping.rb' + - 'opensearch-dsl/Rakefile' + - 'opensearch-transport/lib/opensearch/transport/transport/base.rb' + - 'rake_tasks/update_version.rake' + +# Offense count: 1 +# Configuration parameters: AllowedMethods. +# AllowedMethods: present?, blank?, presence, try, try!, in? +Lint/SafeNavigationChain: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/http/curb.rb' + +# Offense count: 7 +Lint/ShadowingOuterLocalVariable: + Exclude: + - 'opensearch-dsl/test/integration/search_test.rb' + - 'opensearch-dsl/test/unit/search_test.rb' + - 'profile/benchmarking/results.rb' + +# Offense count: 5 +# Configuration parameters: AllowComments, AllowNil. +Lint/SuppressedException: + Exclude: + - 'opensearch-aws-sigv4/bin/opensearch_sigv4_console' + - 'opensearch-ruby/bin/opensearch_ruby_console' + - 'opensearch-transport/test/integration/transport_test.rb' + +# Offense count: 183 +# Configuration parameters: AllowKeywordBlockArguments. +Lint/UnderscorePrefixedVariableName: + Enabled: false + +# Offense count: 1 +# Configuration parameters: Methods. +Lint/UnexpectedBlockArity: + Exclude: + - 'opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/bucket_sort_spec.rb' + +# Offense count: 43 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. +Lint/UnusedBlockArgument: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/http/curb.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/spec/spec_helper.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'opensearch-transport/test/unit/transport_faraday_test.rb' + - 'opensearch-transport/test/unit/transport_manticore_test.rb' + - 'profile/benchmarking/benchmarking_tasks.rake' + - 'profile/benchmarking/complex.rb' + - 'rake_tasks/opensearch_tasks.rake' + - 'rake_tasks/test_tasks.rake' + +# Offense count: 19 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods. +Lint/UnusedMethodArgument: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/connections/selector.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/http/curb.rb' + - 'opensearch-transport/spec/opensearch/connections/selector_spec.rb' + - 'opensearch-transport/test/test_helper.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'profile/benchmarking/complex.rb' + - 'profile/benchmarking/simple.rb' + +# Offense count: 1 +Lint/UriEscapeUnescape: + Exclude: + - 'opensearch-dsl/Rakefile' + +# Offense count: 24 +Lint/UselessAssignment: + Enabled: false + +# Offense count: 5 +# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# CheckDefinitionPathHierarchyRoots: lib, spec, test, src +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Naming/FileName: + Exclude: + - 'opensearch-api/lib/opensearch-api.rb' + - 'opensearch-aws-sigv4/lib/opensearch-aws-sigv4.rb' + - 'opensearch-dsl/lib/opensearch-dsl.rb' + - 'opensearch-ruby/lib/opensearch-ruby.rb' + - 'opensearch-transport/lib/opensearch-transport.rb' + +# Offense count: 5 +# Configuration parameters: EnforcedStyleForLeadingUnderscores. +# SupportedStylesForLeadingUnderscores: disallowed, required, optional +Naming/MemoizedInstanceVariableName: + Exclude: + - 'opensearch-dsl/lib/opensearch/dsl/search/aggregation.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/base.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/http/curb.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/http/faraday.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/http/manticore.rb' + +# Offense count: 4 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: at, by, db, id, in, io, ip, of, on, os, pp, to +Naming/MethodParameterName: + Exclude: + - 'opensearch-dsl/test/integration/search_test.rb' + - 'opensearch-transport/lib/opensearch/transport/redacted.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/base.rb' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: PreferredName. +Naming/RescuedExceptionsVariableName: + Exclude: + - 'profile/benchmarking/benchmarking_tasks.rake' + - 'profile/benchmarking/measurable.rb' + +# Offense count: 2 +RSpec/AnyInstance: + Exclude: + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + +# Offense count: 2 +RSpec/BeforeAfterAll: + Exclude: + - 'spec/spec_helper.rb' + - 'spec/rails_helper.rb' + - 'spec/support/**/*.rb' + - 'opensearch-api/spec/opensearch/api/rest_api_yaml_spec.rb' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +RSpec/ContextMethod: + Exclude: + - 'opensearch-transport/spec/opensearch/connections/collection_spec.rb' + +# Offense count: 19 +# Configuration parameters: Prefixes. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'opensearch-api/spec/opensearch/api/actions/json_builders_spec.rb' + - 'opensearch-ruby/spec/integration/security_disabled/client_integration_spec.rb' + - 'opensearch-ruby/spec/integration/security_enabled/client_integration_spec.rb' + - 'opensearch-ruby/spec/unit/opensearch_product_validation_spec.rb' + - 'opensearch-transport/spec/opensearch/connections/collection_spec.rb' + +# Offense count: 146 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: + Enabled: false + +# Offense count: 5 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: SkipBlocks, EnforcedStyle. +# SupportedStyles: described_class, explicit +RSpec/DescribedClass: + Exclude: + - 'opensearch-api/spec/opensearch/api/api_spec.rb' + - 'opensearch-aws-sigv4/spec/integration/sigv4_client_integration_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + +# Offense count: 1 +RSpec/EmptyExampleGroup: + Exclude: + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +RSpec/EmptyLineAfterFinalLet: + Exclude: + - 'opensearch-transport/spec/opensearch/transport/base_spec.rb' + +# Offense count: 25 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 13 + +# Offense count: 22 +RSpec/ExpectInHook: + Exclude: + - 'opensearch-api/spec/opensearch/api/actions/delete_document_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/exists_document_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/get_document_source_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/get_document_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/indices/delete_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/indices/delete_template_spec.rb' + - 'opensearch-transport/spec/opensearch/connections/collection_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/base_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + +# Offense count: 6 +RSpec/ExpectOutput: + Exclude: + - 'opensearch-ruby/spec/unit/opensearch_product_validation_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + +# Offense count: 119 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Include: **/*_spec*rb*, **/spec/**/* +RSpec/FilePath: + Enabled: false + +# Offense count: 2 +RSpec/IdenticalEqualityAssertion: + Exclude: + - 'opensearch-dsl/spec/opensearch/dsl/search/queries/bool_spec.rb' + +# Offense count: 2 +RSpec/LeakyConstantDeclaration: + Exclude: + - 'opensearch-transport/spec/opensearch/connections/selector_spec.rb' + +# Offense count: 1 +RSpec/MessageChain: + Exclude: + - 'opensearch-aws-sigv4/spec/unit/sigv4_client_spec.rb' + +# Offense count: 44 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: have_received, receive +RSpec/MessageSpies: + Exclude: + - 'opensearch-api/spec/opensearch/api/actions/delete_document_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/exists_document_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/get_document_source_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/get_document_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/indices/delete_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/indices/delete_template_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/indices/exists_alias_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/indices/exists_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/indices/exists_template_spec.rb' + - 'opensearch-api/spec/opensearch/api/utils_spec.rb' + - 'opensearch-api/spec/spec_helper.rb' + - 'opensearch-aws-sigv4/spec/unit/sigv4_client_spec.rb' + - 'opensearch-transport/spec/opensearch/connections/collection_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/base_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + +# Offense count: 69 +RSpec/MultipleExpectations: + Max: 6 + +# Offense count: 54 +# Configuration parameters: AllowSubject. +RSpec/MultipleMemoizedHelpers: + Max: 8 + +# Offense count: 64 +RSpec/NestedGroups: + Max: 6 + +# Offense count: 6 +RSpec/OverwritingSetup: + Exclude: + - 'opensearch-api/spec/opensearch/api/actions/nodes/info_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/nodes/shutdown_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/nodes/stats_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/shutdown/delete_node_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/shutdown/put_node_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/snapshot/repository_analize_spec.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +RSpec/ReceiveCounts: + Exclude: + - 'opensearch-transport/spec/opensearch/transport/base_spec.rb' + +# Offense count: 2 +RSpec/RepeatedDescription: + Exclude: + - 'opensearch-api/spec/opensearch/api/actions/create_pit_spec.rb' + +# Offense count: 8 +RSpec/RepeatedExampleGroupBody: + Exclude: + - 'opensearch-api/spec/opensearch/api/actions/search_spec.rb' + - 'opensearch-api/spec/opensearch/api/utils_spec.rb' + - 'opensearch-dsl/spec/opensearch/dsl/search/aggregations/terms_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + +# Offense count: 20 +RSpec/RepeatedExampleGroupDescription: + Exclude: + - 'opensearch-api/spec/opensearch/api/actions/indices/clone_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/search_spec.rb' + - 'opensearch-dsl/spec/opensearch/dsl/search/aggregations/ip_range_spec.rb' + - 'opensearch-dsl/spec/opensearch/dsl/search/aggregations/missing_spec.rb' + - 'opensearch-dsl/spec/opensearch/dsl/search/aggregations/nested_spec.rb' + - 'opensearch-dsl/spec/opensearch/dsl/search/aggregations/percentile_ranks_spec.rb' + - 'opensearch-dsl/spec/opensearch/dsl/search/aggregations/percentiles_spec.rb' + - 'opensearch-dsl/spec/opensearch/dsl/search/aggregations/range_spec.rb' + - 'opensearch-transport/spec/opensearch/connections/collection_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +RSpec/ScatteredLet: + Exclude: + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + +# Offense count: 26 +RSpec/StubbedMock: + Exclude: + - 'opensearch-api/spec/opensearch/api/actions/delete_document_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/exists_document_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/get_document_source_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/get_document_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/indices/delete_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/indices/delete_template_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/indices/exists_alias_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/indices/exists_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/indices/exists_template_spec.rb' + - 'opensearch-api/spec/opensearch/api/utils_spec.rb' + - 'opensearch-api/spec/spec_helper.rb' + - 'opensearch-transport/spec/opensearch/connections/collection_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + +# Offense count: 1 +RSpec/SubjectStub: + Exclude: + - 'opensearch-aws-sigv4/spec/unit/sigv4_client_spec.rb' + +# Offense count: 29 +# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. +RSpec/VerifiedDoubles: + Exclude: + - 'opensearch-api/spec/opensearch/api/actions/indices/exists_alias_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/indices/exists_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/indices/exists_template_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/ping_spec.rb' + - 'opensearch-api/spec/spec_helper.rb' + - 'opensearch-transport/spec/opensearch/connections/collection_spec.rb' + - 'opensearch-transport/spec/opensearch/connections/selector_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/base_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/sniffer_spec.rb' + +# Offense count: 30 +RSpec/VoidExpect: + Exclude: + - 'opensearch-api/spec/opensearch/api/actions/abort_benchmark_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/benchmark_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/msearch_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/msearch_template_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/search_spec.rb' + - 'opensearch-api/spec/opensearch/api/actions/update_document_spec.rb' + - 'opensearch-ruby/spec/unit/opensearch_product_validation_spec.rb' + - 'opensearch-ruby/spec/unit/wrapper_gem_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + +# Offense count: 3 +# This cop supports safe auto-correction (--auto-correct). +Rake/Desc: + Exclude: + - 'profile/benchmarking/benchmarking_tasks.rake' + - 'rake_tasks/test_tasks.rake' + - 'rake_tasks/update_version.rake' + +# Offense count: 5 +Rake/MethodDefinitionInTask: + Exclude: + - 'rake_tasks/test_tasks.rake' + - 'rake_tasks/unified_release_tasks.rake' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +Security/JSONLoad: + Exclude: + - 'opensearch-dsl/Rakefile' + +# Offense count: 1 +Security/Open: + Exclude: + - 'rake_tasks/test_tasks.rake' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: separated, grouped +Style/AccessorGrouping: + Exclude: + - 'profile/benchmarking/measurable.rb' + +# Offense count: 3 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: prefer_alias, prefer_alias_method +Style/Alias: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/connections/collection.rb' + - 'opensearch-transport/test/test_helper.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, conditionals +Style/AndOr: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/base.rb' + +# Offense count: 21 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, IgnoredMethods, AllowBracesOnProceduralOneLiners, BracesRequiredMethods. +# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces +# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object +# FunctionalMethods: let, let!, subject, watch +# IgnoredMethods: lambda, proc, it +Style/BlockDelimiters: + Exclude: + - 'opensearch-dsl/test/unit/search_test.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/connections/connection.rb' + - 'opensearch-transport/spec/opensearch/connections/selector_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/base_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/test/profile/client_benchmark_test.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: AllowOnConstant. +Style/CaseEquality: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/base.rb' + +# Offense count: 10 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: nested, compact +Style/ClassAndModuleChildren: + Exclude: + - 'opensearch-dsl/test/unit/search_base_aggregation_component_test.rb' + - 'opensearch-transport/test/integration/transport_test.rb' + - 'opensearch-transport/test/profile/client_benchmark_test.rb' + - 'opensearch-transport/test/unit/connection_test.rb' + - 'opensearch-transport/test/unit/response_test.rb' + - 'opensearch-transport/test/unit/serializer_test.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'opensearch-transport/test/unit/transport_curb_test.rb' + - 'opensearch-transport/test/unit/transport_faraday_test.rb' + - 'opensearch-transport/test/unit/transport_manticore_test.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +Style/ColonMethodCall: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/sniffer.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +Style/CommentedKeyword: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/base.rb' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +Style/Dir: + Exclude: + - 'profile/benchmarking/benchmarking_tasks.rake' + - 'profile/benchmarking/measurable.rb' + +# Offense count: 258 +# Configuration parameters: AllowedConstants. +Style/Documentation: + Enabled: false + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: allowed_in_returns, forbidden +Style/DoubleNegation: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/base.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +Style/EachWithObject: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/errors.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +Style/ExpandPathArguments: + Exclude: + - 'opensearch-transport/opensearch-transport.gemspec' + +# Offense count: 22 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: AllowedVars. +Style/FetchEnvVar: + Exclude: + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/spec/spec_helper.rb' + - 'opensearch-transport/test/profile/client_benchmark_test.rb' + - 'opensearch-transport/test/test_helper.rb' + - 'profile/benchmarking/benchmarking_tasks.rake' + - 'profile/benchmarking/measurable.rb' + +# Offense count: 680 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Enabled: false + +# Offense count: 18 +# This cop supports safe auto-correction (--auto-correct). +Style/GlobalStdStream: + Exclude: + - 'opensearch-api/lib/opensearch/api/utils.rb' + - 'opensearch-api/spec/spec_helper.rb' + - 'opensearch-aws-sigv4/lib/opensearch-aws-sigv4.rb' + - 'opensearch-dsl/test/test_helper.rb' + - 'opensearch-transport/lib/opensearch/transport/client.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'rake_tasks/opensearch_tasks.rake' + - 'rake_tasks/test_tasks.rake' + +# Offense count: 3 +# Configuration parameters: AllowedVariables. +Style/GlobalVars: + Exclude: + - 'Rakefile' + - 'opensearch-transport/spec/spec_helper.rb' + +# Offense count: 17 +# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals. +Style/GuardClause: + Exclude: + - 'opensearch-api/lib/opensearch/api/actions/ping.rb' + - 'opensearch-api/lib/opensearch/api/utils.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/aggregation.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/base_aggregation_component.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/base_compound_filter_component.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/filter.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/filters/not.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/filters/query.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/query.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/base.rb' + - 'opensearch-transport/test/test_helper.rb' + - 'profile/benchmarking/results.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: AllowSplatArgument. +Style/HashConversion: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/http/curb.rb' + +# Offense count: 387 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, EnforcedShorthandSyntax, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols. +# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys +# SupportedShorthandSyntax: always, never, either +Style/HashSyntax: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/connections/collection.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/http/curb.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/http/faraday.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/http/manticore.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/test/integration/transport_test.rb' + - 'opensearch-transport/test/unit/connection_test.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'opensearch-transport/test/unit/transport_curb_test.rb' + - 'opensearch-transport/test/unit/transport_faraday_test.rb' + - 'opensearch-transport/test/unit/transport_manticore_test.rb' + - 'profile/benchmarking/benchmarking_tasks.rake' + - 'rake_tasks/opensearch_tasks.rake' + +# Offense count: 1 +# This cop supports unsafe auto-correction (--auto-correct-all). +Style/HashTransformKeys: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/client.rb' + +# Offense count: 1 +# This cop supports unsafe auto-correction (--auto-correct-all). +Style/HashTransformValues: + Exclude: + - 'opensearch-dsl/lib/opensearch/dsl/search/aggregation.rb' + +# Offense count: 29 +# This cop supports safe auto-correction (--auto-correct). +Style/IfUnlessModifier: + Enabled: false + +# Offense count: 1 +# This cop supports unsafe auto-correction (--auto-correct-all). +# Configuration parameters: InverseMethods, InverseBlocks. +Style/InverseMethods: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/base.rb' + +# Offense count: 3 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: line_count_dependent, lambda, literal +Style/Lambda: + Exclude: + - 'opensearch-transport/test/unit/transport_base_test.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +Style/LineEndConcatenation: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/base.rb' + +# Offense count: 8 +Style/MissingRespondToMissing: + Exclude: + - 'opensearch-dsl/lib/opensearch/dsl/search.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/aggregation.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/base_aggregation_component.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/base_compound_filter_component.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/filter.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/filters/not.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/query.rb' + - 'opensearch-ruby/lib/opensearch.rb' + +# Offense count: 5 +Style/MixinUsage: + Exclude: + - 'opensearch-api/spec/rest_yaml_tests_helper.rb' + - 'opensearch-aws-sigv4/bin/opensearch_sigv4_console' + - 'opensearch-ruby/bin/opensearch_ruby_console' + +# Offense count: 15 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, Autocorrect. +# SupportedStyles: module_function, extend_self, forbidden +Style/ModuleFunction: + Exclude: + - 'opensearch-api/lib/opensearch/api/actions/cat/params_registry.rb' + - 'opensearch-api/lib/opensearch/api/actions/cluster/params_registry.rb' + - 'opensearch-api/lib/opensearch/api/actions/dangling_indices/params_registry.rb' + - 'opensearch-api/lib/opensearch/api/actions/features/params_registry.rb' + - 'opensearch-api/lib/opensearch/api/actions/indices/params_registry.rb' + - 'opensearch-api/lib/opensearch/api/actions/ingest/params_registry.rb' + - 'opensearch-api/lib/opensearch/api/actions/nodes/params_registry.rb' + - 'opensearch-api/lib/opensearch/api/actions/params_registry.rb' + - 'opensearch-api/lib/opensearch/api/actions/shutdown/params_registry.rb' + - 'opensearch-api/lib/opensearch/api/actions/snapshot/params_registry.rb' + - 'opensearch-api/lib/opensearch/api/actions/tasks/params_registry.rb' + - 'opensearch-api/lib/opensearch/api/utils.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search.rb' + - 'opensearch-dsl/lib/opensearch/dsl/utils.rb' + - 'profile/benchmarking.rb' + +# Offense count: 3 +Style/MultilineBlockChain: + Exclude: + - 'opensearch-api/Rakefile' + - 'opensearch-api/lib/opensearch/api/actions/msearch.rb' + - 'opensearch-api/lib/opensearch/api/utils.rb' + +# Offense count: 8 +# This cop supports safe auto-correction (--auto-correct). +Style/MultilineIfModifier: + Exclude: + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/test/integration/transport_test.rb' + - 'profile/benchmarking/results.rb' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +Style/MultilineTernaryOperator: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/base.rb' + - 'profile/benchmarking/results.rb' + +# Offense count: 27 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: literals, strict +Style/MutableConstant: + Enabled: false + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +Style/NegatedIfElseCondition: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/http/faraday.rb' + +# Offense count: 30 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: AllowedMethods. +# AllowedMethods: be, be_a, be_an, be_between, be_falsey, be_kind_of, be_instance_of, be_truthy, be_within, eq, eql, end_with, include, match, raise_error, respond_to, start_with +Style/NestedParenthesizedCalls: + Exclude: + - 'opensearch-transport/test/unit/transport_base_test.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedOctalStyle. +# SupportedOctalStyles: zero_with_o, zero_only +Style/NumericLiteralPrefix: + Exclude: + - 'rake_tasks/opensearch_tasks.rake' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: Strict, AllowedNumbers. +Style/NumericLiterals: + MinDigits: 10 + +# Offense count: 2 +# This cop supports unsafe auto-correction (--auto-correct-all). +# Configuration parameters: EnforcedStyle, IgnoredMethods. +# SupportedStyles: predicate, comparison +Style/NumericPredicate: + Exclude: + - 'spec/**/*' + - 'opensearch-transport/lib/opensearch/transport/transport/base.rb' + +# Offense count: 2 +Style/OpenStructUse: + Exclude: + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + +# Offense count: 1 +Style/OptionalArguments: + Exclude: + - 'opensearch-aws-sigv4/lib/opensearch-aws-sigv4.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +Style/ParallelAssignment: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/response.rb' + +# Offense count: 3 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Exclude: + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'opensearch-transport/test/unit/transport_curb_test.rb' + - 'opensearch-transport/test/unit/transport_manticore_test.rb' + +# Offense count: 2 +# This cop supports unsafe auto-correction (--auto-correct-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: short, verbose +Style/PreferredHashMethods: + Exclude: + - 'opensearch-api/lib/opensearch/api/actions/msearch.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/aggregations/range.rb' + +# Offense count: 6 +# This cop supports safe auto-correction (--auto-correct). +Style/Proc: + Exclude: + - 'opensearch-transport/test/unit/transport_base_test.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, AllowedCompactTypes. +# SupportedStyles: compact, exploded +Style/RaiseArgs: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/http/manticore.rb' + +# Offense count: 6 +# This cop supports safe auto-correction (--auto-correct). +Style/RedundantBegin: + Exclude: + - 'profile/benchmarking/benchmarking_tasks.rake' + - 'profile/benchmarking/measurable.rb' + - 'profile/benchmarking/results.rb' + - 'rake_tasks/opensearch_tasks.rake' + - 'rake_tasks/update_version.rake' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +Style/RedundantFreeze: + Exclude: + - 'profile/benchmarking.rb' + +# Offense count: 18 +# This cop supports safe auto-correction (--auto-correct). +Style/RedundantInterpolation: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/connections/connection.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/http/faraday.rb' + - 'profile/benchmarking/benchmarking_tasks.rake' + - 'profile/benchmarking/measurable.rb' + - 'rake_tasks/update_version.rake' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +Style/RedundantParentheses: + Exclude: + - 'profile/benchmarking/measurable.rb' + +# Offense count: 10 +# This cop supports safe auto-correction (--auto-correct). +Style/RedundantRegexpEscape: + Exclude: + - 'opensearch-transport/spec/spec_helper.rb' + - 'opensearch-transport/test/test_helper.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'rake_tasks/update_version.rake' + +# Offense count: 4 +# This cop supports safe auto-correction (--auto-correct). +Style/RedundantSelf: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/connections/connection.rb' + +# Offense count: 9 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, AllowInnerSlashes. +# SupportedStyles: slashes, percent_r, mixed +Style/RegexpLiteral: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/transport/connections/connection.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/http/curb.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/sniffer.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/spec/spec_helper.rb' + - 'opensearch-transport/test/test_helper.rb' + - 'opensearch-transport/test/unit/transport_base_test.rb' + - 'rake_tasks/opensearch_tasks.rake' + +# Offense count: 4 +# This cop supports safe auto-correction (--auto-correct). +Style/RescueModifier: + Exclude: + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/test/profile/client_benchmark_test.rb' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: implicit, explicit +Style/RescueStandardError: + Exclude: + - 'profile/benchmarking/benchmarking_tasks.rake' + - 'profile/benchmarking/measurable.rb' + +# Offense count: 9 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength. +# AllowedMethods: present?, blank?, presence, try, try! +Style/SafeNavigation: + Exclude: + - 'opensearch-api/lib/opensearch/api/utils.rb' + - 'opensearch-dsl/lib/opensearch/dsl/search/base_component.rb' + - 'opensearch-transport/lib/opensearch/transport/client.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/loggable.rb' + +# Offense count: 8 +# This cop supports safe auto-correction (--auto-correct). +Style/SelectByRegexp: + Exclude: + - 'rake_tasks/opensearch_tasks.rake' + - 'rake_tasks/update_version.rake' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: AllowAsExpressionSeparator. +Style/Semicolon: + Exclude: + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: AllowIfMethodIsEmpty. +Style/SingleLineMethods: + Exclude: + - 'opensearch-transport/test/unit/transport_base_test.rb' + +# Offense count: 5 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: RequireEnglish, EnforcedStyle. +# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names +Style/SpecialGlobalVars: + Exclude: + - 'opensearch-api/opensearch-api.gemspec' + - 'opensearch-aws-sigv4/opensearch-aws-sigv4.gemspec' + - 'opensearch-dsl/opensearch-dsl.gemspec' + - 'opensearch-ruby/opensearch-ruby.gemspec' + - 'opensearch-transport/opensearch-transport.gemspec' + +# Offense count: 9 +# This cop supports safe auto-correction (--auto-correct). +Style/StderrPuts: + Exclude: + - 'rake_tasks/opensearch_tasks.rake' + - 'rake_tasks/test_tasks.rake' + +# Offense count: 15 +# This cop supports unsafe auto-correction (--auto-correct-all). +# Configuration parameters: Mode. +Style/StringConcatenation: + Exclude: + - 'opensearch-api/spec/spec_helper.rb' + - 'opensearch-aws-sigv4/lib/opensearch-aws-sigv4.rb' + - 'opensearch-dsl/Rakefile' + - 'opensearch-dsl/test/test_helper.rb' + - 'opensearch-transport/lib/opensearch/transport/redacted.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/base.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/connections/connection.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/test/unit/transport_manticore_test.rb' + - 'rake_tasks/unified_release_tasks.rake' + +# Offense count: 305 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiterals: + Enabled: false + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: . +# SupportedStyles: percent, brackets +Style/SymbolArray: + EnforcedStyle: percent + MinSize: 3 + +# Offense count: 14 +# This cop supports unsafe auto-correction (--auto-correct-all). +# Configuration parameters: AllowMethodsWithArguments, IgnoredMethods, AllowComments. +# IgnoredMethods: respond_to, define_method +Style/SymbolProc: + Exclude: + - 'Rakefile' + - 'opensearch-dsl/lib/opensearch/dsl/search/base_compound_filter_component.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/base.rb' + - 'opensearch-transport/lib/opensearch/transport/transport/connections/collection.rb' + - 'opensearch-transport/spec/opensearch/connections/collection_spec.rb' + - 'opensearch-transport/spec/opensearch/connections/selector_spec.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, AllowSafeAssignment. +# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex +Style/TernaryParentheses: + Exclude: + - 'profile/benchmarking/results.rb' + +# Offense count: 2 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInArrayLiteral: + Exclude: + - 'rake_tasks/test_tasks.rake' + - 'scripts/github_pages_generator.rb' + +# Offense count: 1 +# This cop supports safe auto-correction (--auto-correct). +Style/UnlessElse: + Exclude: + - 'opensearch-transport/test/unit/transport_manticore_test.rb' + +# Offense count: 11 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: EnforcedStyle, MinSize, WordRegex. +# SupportedStyles: percent, brackets +Style/WordArray: + Exclude: + - 'Rakefile' + - 'opensearch-transport/spec/opensearch/connections/collection_spec.rb' + - 'opensearch-transport/spec/opensearch/connections/selector_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/client_spec.rb' + - 'opensearch-transport/spec/opensearch/transport/sniffer_spec.rb' + - 'rake_tasks/test_tasks.rake' + +# Offense count: 1 +# This cop supports unsafe auto-correction (--auto-correct-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: forbid_for_all_comparison_operators, forbid_for_equality_operators_only, require_for_all_comparison_operators, require_for_equality_operators_only +Style/YodaCondition: + Exclude: + - 'opensearch-transport/lib/opensearch/transport/client.rb' + +# Offense count: 650 +# This cop supports safe auto-correction (--auto-correct). +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns, IgnoredPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 474 diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index 2a0120550..358e4c51e 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -1,3 +1,13 @@ +- [Developer Guide](#developer-guide) + - [Getting Started](#getting-started) + - [Git Clone OpenSearch Ruby Repo](#git-clone-opensearch-ruby-repo) + - [Install Prerequisites](#install-prerequisites) + - [Docker](#docker) + - [Build and Test](#build-and-test) + - [Integration Tests](#integration-tests) + - [Linter](#linter) + - [Submitting Changes](#submitting-changes) + # Developer Guide So you want to contribute code to the OpenSearch Ruby client? Excellent! We're glad you're here. Here's what you need to do. @@ -44,6 +54,15 @@ And run: bundle exec rake test:integration ``` +### Linter + +Use RuboCop to auto-lint Ruby code. + +``` +rubocop -a +rubocop --auto-gen-config +``` + ## Submitting Changes -See [CONTRIBUTING](CONTRIBUTING.md). \ No newline at end of file +See [CONTRIBUTING](CONTRIBUTING.md). diff --git a/Gemfile b/Gemfile index 1c13c210f..5ec8e1ca8 100644 --- a/Gemfile +++ b/Gemfile @@ -26,10 +26,10 @@ source 'https://rubygems.org' -gem 'opensearch-api', path: File.expand_path('../opensearch-api', __FILE__), require: false -gem 'opensearch-transport', path: File.expand_path('../opensearch-transport', __FILE__), require: false -gem 'opensearch-ruby', path: File.expand_path('../opensearch-ruby', __FILE__), require: false -gem 'opensearch-aws-sigv4', path: File.expand_path('../opensearch-aws-sigv4', __FILE__), require: false +gem 'opensearch-api', path: File.expand_path('opensearch-api', __dir__), require: false +gem 'opensearch-aws-sigv4', path: File.expand_path('opensearch-aws-sigv4', __dir__), require: false +gem 'opensearch-ruby', path: File.expand_path('opensearch-ruby', __dir__), require: false +gem 'opensearch-transport', path: File.expand_path('opensearch-transport', __dir__), require: false gem 'ansi' gem 'cane' @@ -37,7 +37,10 @@ gem 'mocha' gem 'pry' gem 'rake' gem 'require-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius) -gem 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius) +gem 'rubocop', '~> 1.28.0' +gem 'rubocop-rake' +gem 'rubocop-rspec' +gem 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius) gem 'shoulda-context' gem 'simplecov' gem 'test-unit', '~> 2' diff --git a/Rakefile b/Rakefile index 19f6c566f..11b0a1318 100644 --- a/Rakefile +++ b/Rakefile @@ -27,18 +27,18 @@ # Admin client is used by tests and other rake tasks to communicate with a running cluster. def admin_client $admin_client ||= begin - transport_options = {} - if (hosts = ENV['TEST_OPENSEARCH_SERVER'] || ENV['OPENSEARCH_HOSTS']) - split_hosts = hosts.split(',').map do |host| - /(http\:\/\/)?\S+/.match(host) - end - uri = URI.parse(split_hosts.first[0]) - end - - url = "http://#{uri&.host || 'localhost'}:#{uri&.port || 9200}" - puts "OpenSearch Client url: #{url}" - OpenSearch::Client.new(host: url, transport_options: transport_options) - end + transport_options = {} + if (hosts = ENV.fetch('TEST_OPENSEARCH_SERVER', nil) || ENV.fetch('OPENSEARCH_HOSTS', nil)) + split_hosts = hosts.split(',').map do |host| + %r{(http://)?\S+}.match(host) + end + uri = URI.parse(split_hosts.first[0]) + end + + url = "http://#{uri&.host || 'localhost'}:#{uri&.port || 9200}" + puts "OpenSearch Client url: #{url}" + OpenSearch::Client.new(host: url, transport_options: transport_options) + end end import 'rake_tasks/opensearch_tasks.rake' @@ -54,17 +54,17 @@ SUBPROJECTS = [ 'opensearch-transport', 'opensearch-dsl', 'opensearch-api', - 'opensearch-aws-sigv4', + 'opensearch-aws-sigv4' ].freeze RELEASE_TOGETHER = [ 'opensearch-ruby', 'opensearch-transport', 'opensearch-api', - 'opensearch-aws-sigv4', + 'opensearch-aws-sigv4' ].freeze -CERT_DIR = ENV['CERT_DIR'] +CERT_DIR = ENV.fetch('CERT_DIR', nil) # Import build task after setting constants: import 'rake_tasks/unified_release_tasks.rake' @@ -81,14 +81,14 @@ task :subprojects do puts '-' * 80 SUBPROJECTS.each do |project| commit = `git log --pretty=format:'%h %ar: %s' -1 #{project}` - version = Gem::Specification::load(CURRENT_PATH.join(project, "#{project}.gemspec").to_s).version.to_s - puts "#{version}".ljust(10) + - "| \e[1m#{project.ljust(SUBPROJECTS.map {|s| s.length}.max)}\e[0m | #{commit[ 0..80]}..." + version = Gem::Specification.load(CURRENT_PATH.join(project, "#{project}.gemspec").to_s).version.to_s + puts version.to_s.ljust(10) + + "| \e[1m#{project.ljust(SUBPROJECTS.map { |s| s.length }.max)}\e[0m | #{commit[0..80]}..." end end desc "Alias for `bundle:install`" -task :bundle => 'bundle:install' +task bundle: 'bundle:install' namespace :bundle do desc "Run `bundle install` in all subprojects" @@ -108,7 +108,6 @@ namespace :bundle do end end - require_relative 'scripts/github_pages_generator' desc "Generate documentation for all subprojects to be published to gh-pages" task :gh_pages do @@ -119,7 +118,7 @@ desc "Generate documentation for all subprojects" task :doc do SUBPROJECTS.each do |project| sh "cd #{CURRENT_PATH.join(project)} && rake doc" - puts '-'*80 + puts '-' * 80 end end diff --git a/opensearch-api/Gemfile b/opensearch-api/Gemfile index c75bd4d62..d5c928b55 100644 --- a/opensearch-api/Gemfile +++ b/opensearch-api/Gemfile @@ -29,12 +29,12 @@ source 'https://rubygems.org' # Specify your gem's dependencies in opensearch-api.gemspec gemspec -if File.exist? File.expand_path("../../opensearch-transport", __FILE__) - gem 'opensearch-transport', path: File.expand_path("../../opensearch-transport", __FILE__), require: true +if File.exist? File.expand_path('../opensearch-transport', __dir__) + gem 'opensearch-transport', path: File.expand_path('../opensearch-transport', __dir__), require: true end -if File.exist? File.expand_path("../../opensearch-ruby/opensearch-ruby.gemspec", __FILE__) - gem 'opensearch-ruby', path: File.expand_path("../../opensearch-ruby", __FILE__), require: false +if File.exist? File.expand_path('../opensearch-ruby/opensearch-ruby.gemspec', __dir__) + gem 'opensearch-ruby', path: File.expand_path('../opensearch-ruby', __dir__), require: false end group :development do diff --git a/opensearch-api/Rakefile b/opensearch-api/Rakefile index 230a4ddb5..b400c5a62 100644 --- a/opensearch-api/Rakefile +++ b/opensearch-api/Rakefile @@ -48,26 +48,26 @@ namespace :test do t.exclude_pattern = 'spec/**{,/*/**}/rest_api_yaml_spec.rb' end - desc "Run Rest API Spec tests" + desc 'Run Rest API Spec tests' RSpec::Core::RakeTask.new(:rest_api) do |t| require 'opensearch' # Check if a test cluster is running begin - url = ENV['TEST_CLUSTER_URL'] || ENV['TEST_OPENSEARCH_SERVER'] - url = "http://localhost:#{ENV['TEST_CLUSTER_PORT'] || 9200}" unless url - client = OpenSearch::Client.new :url => url + url = ENV.fetch('TEST_CLUSTER_URL', nil) || ENV.fetch('TEST_OPENSEARCH_SERVER', nil) + url ||= "http://localhost:#{ENV.fetch('TEST_CLUSTER_PORT', nil) || 9200}" + client = OpenSearch::Client.new url: url os_version_info = client.info['version'] version_number = os_version_info['number'] - build_hash = os_version_info['build_hash'] + build_hash = os_version_info['build_hash'] rescue Faraday::ConnectionFailed - STDERR.puts "[!] Test cluster not running?" + warn '[!] Test cluster not running?' exit 1 end t.pattern = 'spec/**{,/*/**}/rest_api_yaml_spec.rb' end - desc "Run integration tests" + desc 'Run integration tests' task :integration do Rake::Task['test:rest_api'].invoke end @@ -78,9 +78,9 @@ namespace :test do Rake::Task['test:integration'].invoke end - def refresh_artifacts(build_hash, version_number) + def refresh_artifacts(build_hash, _version_number) unless build_hash - STDERR.puts "[!] Cannot determine checkout build hash -- server not running" + warn '[!] Cannot determine checkout build hash -- server not running' exit(1) end @@ -89,7 +89,7 @@ namespace :test do `curl -s -o #{filename}` unless File.exist?("./#{filename}") - STDERR.puts '[!] Couldn\'t download artifacts file' + warn '[!] Couldn\'t download artifacts file' exit 1 end @@ -99,14 +99,16 @@ namespace :test do a.dig('projects', 'opensearch', 'commit_hash') == build_hash end.first # Dig into the opensearch packages, search for the rest-resources-zip package and catch the URL: - zip_url = build_hash_artifact.dig('projects', 'opensearch', 'packages').select { |k,v| k =~ /rest-resources-zip/ }.map { | _, v| v['url'] }.first + zip_url = build_hash_artifact.dig('projects', 'opensearch', 'packages').select do |k, _v| + k =~ /rest-resources-zip/ + end.map { |_, v| v['url'] }.first filename = zip_url.split('/').last puts 'Downloading zip file:' `curl -s #{zip_url} -o tmp/#{filename}` unless File.exist?("./tmp/#{filename}") - STDERR.puts '[!] Couldn\'t download artifact' + warn '[!] Couldn\'t download artifact' exit 1 end @@ -119,7 +121,7 @@ end require 'yard' YARD::Rake::YardocTask.new(:doc) do |t| - t.options = %w| --embed-mixins --markup=markdown | + t.options = %w[--embed-mixins --markup=markdown] end # ----- Code analysis tasks --------------------------------------------------- diff --git a/opensearch-api/lib/opensearch/api.rb b/opensearch-api/lib/opensearch/api.rb index 29254595c..6750ac388 100644 --- a/opensearch-api/lib/opensearch/api.rb +++ b/opensearch-api/lib/opensearch/api.rb @@ -24,17 +24,17 @@ # specific language governing permissions and limitations # under the License. -require "cgi" -require "multi_json" +require 'cgi' +require 'multi_json' -require "opensearch/api/version" -require "opensearch/api/namespace/common" -require "opensearch/api/utils" -require "opensearch/api/actions/params_registry" +require 'opensearch/api/version' +require 'opensearch/api/namespace/common' +require 'opensearch/api/utils' +require 'opensearch/api/actions/params_registry' -Dir[ File.expand_path('../api/actions/**/params_registry.rb', __FILE__) ].each { |f| require f } -Dir[ File.expand_path('../api/actions/**/*.rb', __FILE__) ].each { |f| require f } -Dir[ File.expand_path('../api/namespace/**/*.rb', __FILE__) ].each { |f| require f } +Dir[File.expand_path('api/actions/**/params_registry.rb', __dir__)].each { |f| require f } +Dir[File.expand_path('api/actions/**/*.rb', __dir__)].each { |f| require f } +Dir[File.expand_path('api/namespace/**/*.rb', __dir__)].each { |f| require f } module OpenSearch module API diff --git a/opensearch-api/lib/opensearch/api/actions/benchmark.rb b/opensearch-api/lib/opensearch/api/actions/benchmark.rb index 153cafe10..3d2201f49 100644 --- a/opensearch-api/lib/opensearch/api/actions/benchmark.rb +++ b/opensearch-api/lib/opensearch/api/actions/benchmark.rb @@ -72,7 +72,7 @@ module Actions # def benchmark(arguments = {}) method = HTTP_PUT - path = "_bench" + path = '_bench' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] diff --git a/opensearch-api/lib/opensearch/api/actions/bulk.rb b/opensearch-api/lib/opensearch/api/actions/bulk.rb index 29e833df6..c7d004db4 100644 --- a/opensearch-api/lib/opensearch/api/actions/bulk.rb +++ b/opensearch-api/lib/opensearch/api/actions/bulk.rb @@ -57,34 +57,34 @@ def bulk(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_bulk" else - "_bulk" + '_bulk' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] - if body.is_a? Array - payload = OpenSearch::API::Utils.__bulkify(body) - else - payload = body - end + payload = if body.is_a? Array + OpenSearch::API::Utils.__bulkify(body) + else + body + end - headers.merge!("Content-Type" => "application/x-ndjson") + headers.merge!('Content-Type' => 'application/x-ndjson') perform_request(method, path, params, payload, headers).body end # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:bulk, [ - :wait_for_active_shards, - :refresh, - :routing, - :timeout, - :_source, - :_source_excludes, - :_source_includes, - :pipeline, - :require_alias + ParamsRegistry.register(:bulk, %i[ + wait_for_active_shards + refresh + routing + timeout + _source + _source_excludes + _source_includes + pipeline + require_alias ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/aliases.rb b/opensearch-api/lib/opensearch/api/actions/cat/aliases.rb index a3029676c..3752da589 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/aliases.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/aliases.rb @@ -52,7 +52,7 @@ def aliases(arguments = {}) path = if _name "_cat/aliases/#{Utils.__listify(_name)}" else - "_cat/aliases" + '_cat/aliases' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) params[:h] = Utils.__listify(params[:h]) if params[:h] @@ -64,14 +64,14 @@ def aliases(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:aliases, [ - :format, - :local, - :h, - :help, - :s, - :v, - :expand_wildcards + ParamsRegistry.register(:aliases, %i[ + format + local + h + help + s + v + expand_wildcards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/all_pit_segments.rb b/opensearch-api/lib/opensearch/api/actions/cat/all_pit_segments.rb index edeccc85d..0ca3aed73 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/all_pit_segments.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/all_pit_segments.rb @@ -23,7 +23,6 @@ def all_pit_segments(arguments = {}) arguments = arguments.clone headers = arguments.delete(:headers) || {} - method = OpenSearch::API::HTTP_GET path = '_cat/pit_segments/_all' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -33,12 +32,12 @@ def all_pit_segments(arguments = {}) perform_request(method, path, params, body, headers).body end - ParamsRegistry.register(:all_pit_segments, [ - :format, - :h, - :help, - :s, - :v + ParamsRegistry.register(:all_pit_segments, %i[ + format + h + help + s + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/allocation.rb b/opensearch-api/lib/opensearch/api/actions/cat/allocation.rb index 7d2649b2a..285c1e33f 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/allocation.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/allocation.rb @@ -54,7 +54,7 @@ def allocation(arguments = {}) path = if _node_id "_cat/allocation/#{Utils.__listify(_node_id)}" else - "_cat/allocation" + '_cat/allocation' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) params[:h] = Utils.__listify(params[:h]) if params[:h] @@ -66,16 +66,16 @@ def allocation(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:allocation, [ - :format, - :bytes, - :local, - :master_timeout, - :cluster_manager_timeout, - :h, - :help, - :s, - :v + ParamsRegistry.register(:allocation, %i[ + format + bytes + local + master_timeout + cluster_manager_timeout + h + help + s + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/count.rb b/opensearch-api/lib/opensearch/api/actions/cat/count.rb index da40100ab..7cd6845cf 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/count.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/count.rb @@ -50,7 +50,7 @@ def count(arguments = {}) path = if _index "_cat/count/#{Utils.__listify(_index)}" else - "_cat/count" + '_cat/count' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) params[:h] = Utils.__listify(params[:h]) if params[:h] @@ -62,12 +62,12 @@ def count(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:count, [ - :format, - :h, - :help, - :s, - :v + ParamsRegistry.register(:count, %i[ + format + h + help + s + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/fielddata.rb b/opensearch-api/lib/opensearch/api/actions/cat/fielddata.rb index 37f7eaf81..b99be5bec 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/fielddata.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/fielddata.rb @@ -51,7 +51,7 @@ def fielddata(arguments = {}) path = if _fields "_cat/fielddata/#{Utils.__listify(_fields)}" else - "_cat/fielddata" + '_cat/fielddata' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -62,14 +62,14 @@ def fielddata(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:fielddata, [ - :format, - :bytes, - :h, - :help, - :s, - :v, - :fields + ParamsRegistry.register(:fielddata, %i[ + format + bytes + h + help + s + v + fields ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/health.rb b/opensearch-api/lib/opensearch/api/actions/cat/health.rb index a465a5857..213d5f585 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/health.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/health.rb @@ -46,7 +46,7 @@ def health(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_cat/health" + path = '_cat/health' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) params[:h] = Utils.__listify(params[:h]) if params[:h] @@ -57,14 +57,14 @@ def health(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:health, [ - :format, - :h, - :help, - :s, - :time, - :ts, - :v + ParamsRegistry.register(:health, %i[ + format + h + help + s + time + ts + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/help.rb b/opensearch-api/lib/opensearch/api/actions/cat/help.rb index 97dea4af2..ad0d36f74 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/help.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/help.rb @@ -41,7 +41,7 @@ def help(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_cat" + path = '_cat' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil @@ -51,9 +51,9 @@ def help(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:help, [ - :help, - :s + ParamsRegistry.register(:help, %i[ + help + s ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/indices.rb b/opensearch-api/lib/opensearch/api/actions/cat/indices.rb index d9df4e828..e01021ca8 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/indices.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/indices.rb @@ -33,7 +33,7 @@ module Actions # @option arguments [List] :index A comma-separated list of index names to limit the returned information # @option arguments [String] :format a short version of the Accept header, e.g. json, yaml # @option arguments [String] :bytes The unit in which to display byte values (options: b, k, kb, m, mb, g, gb, t, tb, p, pb) - # @option arguments [Boolean] :local Return local information, do not retrieve the state from cluster_manager node (default: false) + # @option arguments [Boolean] :local Return local information, do not retrieve the state from cluster_manager node (default: false) # @option arguments [Time] :master_timeout (DEPRECATED: use cluster_manager_timeout instead) Explicit operation timeout for connection to master node # @option arguments [Time] :cluster_manager_timeout Explicit operation timeout for connection to cluster_manager node # @option arguments [List] :h Comma-separated list of column names to display @@ -59,7 +59,7 @@ def indices(arguments = {}) path = if _index "_cat/indices/#{Utils.__listify(_index)}" else - "_cat/indices" + '_cat/indices' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) params[:h] = Utils.__listify(params[:h]) if params[:h] @@ -71,21 +71,21 @@ def indices(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:indices, [ - :format, - :bytes, - :local, - :master_timeout, - :cluster_manager_timeout, - :h, - :health, - :help, - :pri, - :s, - :time, - :v, - :include_unloaded_segments, - :expand_wildcards + ParamsRegistry.register(:indices, %i[ + format + bytes + local + master_timeout + cluster_manager_timeout + h + health + help + pri + s + time + v + include_unloaded_segments + expand_wildcards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/master.rb b/opensearch-api/lib/opensearch/api/actions/cat/master.rb index dad4a967a..b72528ab4 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/master.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/master.rb @@ -23,7 +23,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. - + # @deprecated Please use cluster_manager instead. module OpenSearch module API @@ -47,7 +47,7 @@ def master(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_cat/master" + path = '_cat/master' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil @@ -57,15 +57,15 @@ def master(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:master, [ - :format, - :local, - :master_timeout, - :cluster_manager_timeout, - :h, - :help, - :s, - :v + ParamsRegistry.register(:master, %i[ + format + local + master_timeout + cluster_manager_timeout + h + help + s + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/nodeattrs.rb b/opensearch-api/lib/opensearch/api/actions/cat/nodeattrs.rb index ef34d1cb3..3970142db 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/nodeattrs.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/nodeattrs.rb @@ -47,7 +47,7 @@ def nodeattrs(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_cat/nodeattrs" + path = '_cat/nodeattrs' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil @@ -57,15 +57,15 @@ def nodeattrs(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:nodeattrs, [ - :format, - :local, - :master_timeout, - :cluster_manager_timeout, - :h, - :help, - :s, - :v + ParamsRegistry.register(:nodeattrs, %i[ + format + local + master_timeout + cluster_manager_timeout + h + help + s + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/nodes.rb b/opensearch-api/lib/opensearch/api/actions/cat/nodes.rb index 29a75b05d..e09a7bc27 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/nodes.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/nodes.rb @@ -51,7 +51,7 @@ def nodes(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_cat/nodes" + path = '_cat/nodes' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) params[:h] = Utils.__listify(params[:h], escape: false) if params[:h] @@ -62,19 +62,19 @@ def nodes(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:nodes, [ - :bytes, - :format, - :full_id, - :local, - :master_timeout, - :cluster_manager_timeout, - :h, - :help, - :s, - :time, - :v, - :include_unloaded_segments + ParamsRegistry.register(:nodes, %i[ + bytes + format + full_id + local + master_timeout + cluster_manager_timeout + h + help + s + time + v + include_unloaded_segments ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/pending_tasks.rb b/opensearch-api/lib/opensearch/api/actions/cat/pending_tasks.rb index c3f325d5a..1763ac708 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/pending_tasks.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/pending_tasks.rb @@ -48,7 +48,7 @@ def pending_tasks(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_cat/pending_tasks" + path = '_cat/pending_tasks' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) params[:h] = Utils.__listify(params[:h]) if params[:h] @@ -59,16 +59,16 @@ def pending_tasks(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:pending_tasks, [ - :format, - :local, - :master_timeout, - :cluster_manager_timeout, - :h, - :help, - :s, - :time, - :v + ParamsRegistry.register(:pending_tasks, %i[ + format + local + master_timeout + cluster_manager_timeout + h + help + s + time + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/pit_segments.rb b/opensearch-api/lib/opensearch/api/actions/cat/pit_segments.rb index 70baba9e5..9d41fcf8a 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/pit_segments.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/pit_segments.rb @@ -26,7 +26,6 @@ def pit_segments(arguments = {}) arguments = arguments.clone headers = arguments.delete(:headers) || {} - method = OpenSearch::API::HTTP_GET path = '_cat/pit_segments' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -36,12 +35,12 @@ def pit_segments(arguments = {}) perform_request(method, path, params, body, headers).body end - ParamsRegistry.register(:pit_segments, [ - :format, - :h, - :help, - :s, - :v + ParamsRegistry.register(:pit_segments, %i[ + format + h + help + s + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/plugins.rb b/opensearch-api/lib/opensearch/api/actions/cat/plugins.rb index c0c8ae92a..c0644888d 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/plugins.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/plugins.rb @@ -48,7 +48,7 @@ def plugins(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_cat/plugins" + path = '_cat/plugins' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil @@ -58,16 +58,16 @@ def plugins(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:plugins, [ - :format, - :local, - :master_timeout, - :cluster_manager_timeout, - :h, - :help, - :include_bootstrap, - :s, - :v + ParamsRegistry.register(:plugins, %i[ + format + local + master_timeout + cluster_manager_timeout + h + help + include_bootstrap + s + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/recovery.rb b/opensearch-api/lib/opensearch/api/actions/cat/recovery.rb index 1cfff5756..c31707c13 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/recovery.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/recovery.rb @@ -54,7 +54,7 @@ def recovery(arguments = {}) path = if _index "_cat/recovery/#{Utils.__listify(_index)}" else - "_cat/recovery" + '_cat/recovery' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) params[:h] = Utils.__listify(params[:h]) if params[:h] @@ -66,17 +66,17 @@ def recovery(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:recovery, [ - :format, - :active_only, - :bytes, - :detailed, - :h, - :help, - :index, - :s, - :time, - :v + ParamsRegistry.register(:recovery, %i[ + format + active_only + bytes + detailed + h + help + index + s + time + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/repositories.rb b/opensearch-api/lib/opensearch/api/actions/cat/repositories.rb index bf486e29d..902722674 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/repositories.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/repositories.rb @@ -24,7 +24,6 @@ # specific language governing permissions and limitations # under the License. - module OpenSearch module API module Cat @@ -48,7 +47,7 @@ def repositories(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_cat/repositories" + path = '_cat/repositories' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil @@ -58,15 +57,15 @@ def repositories(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:repositories, [ - :format, - :local, - :master_timeout, - :cluster_manager_timeout, - :h, - :help, - :s, - :v + ParamsRegistry.register(:repositories, %i[ + format + local + master_timeout + cluster_manager_timeout + h + help + s + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/segments.rb b/opensearch-api/lib/opensearch/api/actions/cat/segments.rb index 0c138a164..25170e7d9 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/segments.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/segments.rb @@ -51,7 +51,7 @@ def segments(arguments = {}) path = if _index "_cat/segments/#{Utils.__listify(_index)}" else - "_cat/segments" + '_cat/segments' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -62,13 +62,13 @@ def segments(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:segments, [ - :format, - :bytes, - :h, - :help, - :s, - :v + ParamsRegistry.register(:segments, %i[ + format + bytes + h + help + s + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/shards.rb b/opensearch-api/lib/opensearch/api/actions/cat/shards.rb index 24bb9e6b2..2523de75d 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/shards.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/shards.rb @@ -55,7 +55,7 @@ def shards(arguments = {}) path = if _index "_cat/shards/#{Utils.__listify(_index)}" else - "_cat/shards" + '_cat/shards' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) params[:h] = Utils.__listify(params[:h]) if params[:h] @@ -67,17 +67,17 @@ def shards(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:shards, [ - :format, - :bytes, - :local, - :master_timeout, - :cluster_manager_timeout, - :h, - :help, - :s, - :time, - :v + ParamsRegistry.register(:shards, %i[ + format + bytes + local + master_timeout + cluster_manager_timeout + h + help + s + time + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/snapshots.rb b/opensearch-api/lib/opensearch/api/actions/cat/snapshots.rb index 3ca82c48f..47387c48c 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/snapshots.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/snapshots.rb @@ -54,7 +54,7 @@ def snapshots(arguments = {}) path = if _repository "_cat/snapshots/#{Utils.__listify(_repository)}" else - "_cat/snapshots" + '_cat/snapshots' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -65,16 +65,16 @@ def snapshots(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:snapshots, [ - :format, - :ignore_unavailable, - :master_timeout, - :cluster_manager_timeout, - :h, - :help, - :s, - :time, - :v + ParamsRegistry.register(:snapshots, %i[ + format + ignore_unavailable + master_timeout + cluster_manager_timeout + h + help + s + time + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/tasks.rb b/opensearch-api/lib/opensearch/api/actions/cat/tasks.rb index fa818f5f8..f47b50157 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/tasks.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/tasks.rb @@ -49,7 +49,7 @@ def tasks(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_cat/tasks" + path = '_cat/tasks' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil @@ -59,17 +59,17 @@ def tasks(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:tasks, [ - :format, - :nodes, - :actions, - :detailed, - :parent_task_id, - :h, - :help, - :s, - :time, - :v + ParamsRegistry.register(:tasks, %i[ + format + nodes + actions + detailed + parent_task_id + h + help + s + time + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/templates.rb b/opensearch-api/lib/opensearch/api/actions/cat/templates.rb index f17d02a53..e7bdc77f9 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/templates.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/templates.rb @@ -53,7 +53,7 @@ def templates(arguments = {}) path = if _name "_cat/templates/#{Utils.__listify(_name)}" else - "_cat/templates" + '_cat/templates' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -64,15 +64,15 @@ def templates(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:templates, [ - :format, - :local, - :master_timeout, - :cluster_manager_timeout, - :h, - :help, - :s, - :v + ParamsRegistry.register(:templates, %i[ + format + local + master_timeout + cluster_manager_timeout + h + help + s + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cat/thread_pool.rb b/opensearch-api/lib/opensearch/api/actions/cat/thread_pool.rb index a92aa9563..1d5154b0c 100644 --- a/opensearch-api/lib/opensearch/api/actions/cat/thread_pool.rb +++ b/opensearch-api/lib/opensearch/api/actions/cat/thread_pool.rb @@ -55,7 +55,7 @@ def thread_pool(arguments = {}) path = if _thread_pool_patterns "_cat/thread_pool/#{Utils.__listify(_thread_pool_patterns)}" else - "_cat/thread_pool" + '_cat/thread_pool' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) params[:h] = Utils.__listify(params[:h]) if params[:h] @@ -67,16 +67,16 @@ def thread_pool(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:thread_pool, [ - :format, - :size, - :local, - :master_timeout, - :cluster_manager_timeout, - :h, - :help, - :s, - :v + ParamsRegistry.register(:thread_pool, %i[ + format + size + local + master_timeout + cluster_manager_timeout + h + help + s + v ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/clear_scroll.rb b/opensearch-api/lib/opensearch/api/actions/clear_scroll.rb index e621a3fd9..64c5d3de2 100644 --- a/opensearch-api/lib/opensearch/api/actions/clear_scroll.rb +++ b/opensearch-api/lib/opensearch/api/actions/clear_scroll.rb @@ -50,7 +50,7 @@ def clear_scroll(arguments = {}) path = if _scroll_id "_search/scroll/#{Utils.__listify(_scroll_id)}" else - "_search/scroll" + '_search/scroll' end params = {} diff --git a/opensearch-api/lib/opensearch/api/actions/cluster/allocation_explain.rb b/opensearch-api/lib/opensearch/api/actions/cluster/allocation_explain.rb index 44153c588..291fdc5e9 100644 --- a/opensearch-api/lib/opensearch/api/actions/cluster/allocation_explain.rb +++ b/opensearch-api/lib/opensearch/api/actions/cluster/allocation_explain.rb @@ -47,7 +47,7 @@ def allocation_explain(arguments = {}) OpenSearch::API::HTTP_GET end - path = "_cluster/allocation/explain" + path = '_cluster/allocation/explain' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] @@ -57,9 +57,9 @@ def allocation_explain(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:allocation_explain, [ - :include_yes_decisions, - :include_disk_info + ParamsRegistry.register(:allocation_explain, %i[ + include_yes_decisions + include_disk_info ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cluster/delete_component_template.rb b/opensearch-api/lib/opensearch/api/actions/cluster/delete_component_template.rb index 9fa138f6d..c44a9eaec 100644 --- a/opensearch-api/lib/opensearch/api/actions/cluster/delete_component_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/cluster/delete_component_template.rb @@ -57,10 +57,10 @@ def delete_component_template(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:delete_component_template, [ - :timeout, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:delete_component_template, %i[ + timeout + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cluster/delete_voting_config_exclusions.rb b/opensearch-api/lib/opensearch/api/actions/cluster/delete_voting_config_exclusions.rb index 917d948b5..b6f42f1b4 100644 --- a/opensearch-api/lib/opensearch/api/actions/cluster/delete_voting_config_exclusions.rb +++ b/opensearch-api/lib/opensearch/api/actions/cluster/delete_voting_config_exclusions.rb @@ -40,7 +40,7 @@ def delete_voting_config_exclusions(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_DELETE - path = "_cluster/voting_config_exclusions" + path = '_cluster/voting_config_exclusions' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil diff --git a/opensearch-api/lib/opensearch/api/actions/cluster/exists_component_template.rb b/opensearch-api/lib/opensearch/api/actions/cluster/exists_component_template.rb index d568ab6aa..324bd8453 100644 --- a/opensearch-api/lib/opensearch/api/actions/cluster/exists_component_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/cluster/exists_component_template.rb @@ -54,15 +54,15 @@ def exists_component_template(arguments = {}) perform_request(method, path, params, body, headers).body end - alias_method :exists_component_template?, :exists_component_template + alias exists_component_template? exists_component_template # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:exists_component_template, [ - :master_timeout, - :cluster_manager_timeout, - :local + ParamsRegistry.register(:exists_component_template, %i[ + master_timeout + cluster_manager_timeout + local ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cluster/get_component_template.rb b/opensearch-api/lib/opensearch/api/actions/cluster/get_component_template.rb index 4a7b29eb4..6c1f1249b 100644 --- a/opensearch-api/lib/opensearch/api/actions/cluster/get_component_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/cluster/get_component_template.rb @@ -48,7 +48,7 @@ def get_component_template(arguments = {}) path = if _name "_component_template/#{Utils.__listify(_name)}" else - "_component_template" + '_component_template' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -59,10 +59,10 @@ def get_component_template(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get_component_template, [ - :master_timeout, - :cluster_manager_timeout, - :local + ParamsRegistry.register(:get_component_template, %i[ + master_timeout + cluster_manager_timeout + local ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cluster/get_settings.rb b/opensearch-api/lib/opensearch/api/actions/cluster/get_settings.rb index 74ab37659..f9711d9a1 100644 --- a/opensearch-api/lib/opensearch/api/actions/cluster/get_settings.rb +++ b/opensearch-api/lib/opensearch/api/actions/cluster/get_settings.rb @@ -44,7 +44,7 @@ def get_settings(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_cluster/settings" + path = '_cluster/settings' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil @@ -54,12 +54,12 @@ def get_settings(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get_settings, [ - :flat_settings, - :master_timeout, - :cluster_manager_timeout, - :timeout, - :include_defaults + ParamsRegistry.register(:get_settings, %i[ + flat_settings + master_timeout + cluster_manager_timeout + timeout + include_defaults ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cluster/health.rb b/opensearch-api/lib/opensearch/api/actions/cluster/health.rb index 76bb55c25..d9505c6dc 100644 --- a/opensearch-api/lib/opensearch/api/actions/cluster/health.rb +++ b/opensearch-api/lib/opensearch/api/actions/cluster/health.rb @@ -57,7 +57,7 @@ def health(arguments = {}) path = if _index "_cluster/health/#{Utils.__listify(_index)}" else - "_cluster/health" + '_cluster/health' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -68,19 +68,19 @@ def health(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:health, [ - :expand_wildcards, - :level, - :local, - :master_timeout, - :cluster_manager_timeout, - :timeout, - :wait_for_active_shards, - :wait_for_nodes, - :wait_for_events, - :wait_for_no_relocating_shards, - :wait_for_no_initializing_shards, - :wait_for_status + ParamsRegistry.register(:health, %i[ + expand_wildcards + level + local + master_timeout + cluster_manager_timeout + timeout + wait_for_active_shards + wait_for_nodes + wait_for_events + wait_for_no_relocating_shards + wait_for_no_initializing_shards + wait_for_status ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cluster/pending_tasks.rb b/opensearch-api/lib/opensearch/api/actions/cluster/pending_tasks.rb index 8f0a13f32..ee3ecb20e 100644 --- a/opensearch-api/lib/opensearch/api/actions/cluster/pending_tasks.rb +++ b/opensearch-api/lib/opensearch/api/actions/cluster/pending_tasks.rb @@ -43,7 +43,7 @@ def pending_tasks(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_cluster/pending_tasks" + path = '_cluster/pending_tasks' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil @@ -53,10 +53,10 @@ def pending_tasks(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:pending_tasks, [ - :local, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:pending_tasks, %i[ + local + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cluster/post_voting_config_exclusions.rb b/opensearch-api/lib/opensearch/api/actions/cluster/post_voting_config_exclusions.rb index 96348fb8b..7936ecd65 100644 --- a/opensearch-api/lib/opensearch/api/actions/cluster/post_voting_config_exclusions.rb +++ b/opensearch-api/lib/opensearch/api/actions/cluster/post_voting_config_exclusions.rb @@ -42,7 +42,7 @@ def post_voting_config_exclusions(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_POST - path = "_cluster/voting_config_exclusions" + path = '_cluster/voting_config_exclusions' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil @@ -52,10 +52,10 @@ def post_voting_config_exclusions(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:post_voting_config_exclusions, [ - :node_ids, - :node_names, - :timeout + ParamsRegistry.register(:post_voting_config_exclusions, %i[ + node_ids + node_names + timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cluster/put_component_template.rb b/opensearch-api/lib/opensearch/api/actions/cluster/put_component_template.rb index daa9c0282..a5e3530e2 100644 --- a/opensearch-api/lib/opensearch/api/actions/cluster/put_component_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/cluster/put_component_template.rb @@ -60,11 +60,11 @@ def put_component_template(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:put_component_template, [ - :create, - :timeout, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:put_component_template, %i[ + create + timeout + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cluster/put_settings.rb b/opensearch-api/lib/opensearch/api/actions/cluster/put_settings.rb index 2ad8fa3be..d2c60a59b 100644 --- a/opensearch-api/lib/opensearch/api/actions/cluster/put_settings.rb +++ b/opensearch-api/lib/opensearch/api/actions/cluster/put_settings.rb @@ -46,7 +46,7 @@ def put_settings(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_PUT - path = "_cluster/settings" + path = '_cluster/settings' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] || {} @@ -56,11 +56,11 @@ def put_settings(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:put_settings, [ - :flat_settings, - :master_timeout, - :cluster_manager_timeout, - :timeout + ParamsRegistry.register(:put_settings, %i[ + flat_settings + master_timeout + cluster_manager_timeout + timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cluster/remote_info.rb b/opensearch-api/lib/opensearch/api/actions/cluster/remote_info.rb index e0600a36b..f3d3ccbb0 100644 --- a/opensearch-api/lib/opensearch/api/actions/cluster/remote_info.rb +++ b/opensearch-api/lib/opensearch/api/actions/cluster/remote_info.rb @@ -39,7 +39,7 @@ def remote_info(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_remote/info" + path = '_remote/info' params = {} body = nil diff --git a/opensearch-api/lib/opensearch/api/actions/cluster/reroute.rb b/opensearch-api/lib/opensearch/api/actions/cluster/reroute.rb index 0e0a1b010..8ed9afced 100644 --- a/opensearch-api/lib/opensearch/api/actions/cluster/reroute.rb +++ b/opensearch-api/lib/opensearch/api/actions/cluster/reroute.rb @@ -47,7 +47,7 @@ def reroute(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_POST - path = "_cluster/reroute" + path = '_cluster/reroute' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] || {} @@ -57,14 +57,14 @@ def reroute(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:reroute, [ - :dry_run, - :explain, - :retry_failed, - :metric, - :master_timeout, - :cluster_manager_timeout, - :timeout + ParamsRegistry.register(:reroute, %i[ + dry_run + explain + retry_failed + metric + master_timeout + cluster_manager_timeout + timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cluster/state.rb b/opensearch-api/lib/opensearch/api/actions/cluster/state.rb index cfef77322..55e6ba1bc 100644 --- a/opensearch-api/lib/opensearch/api/actions/cluster/state.rb +++ b/opensearch-api/lib/opensearch/api/actions/cluster/state.rb @@ -59,7 +59,7 @@ def state(arguments = {}) elsif _metric "_cluster/state/#{Utils.__listify(_metric)}" else - "_cluster/state" + '_cluster/state' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -70,16 +70,16 @@ def state(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:state, [ - :local, - :master_timeout, - :cluster_manager_timeout, - :flat_settings, - :wait_for_metadata_version, - :wait_for_timeout, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards + ParamsRegistry.register(:state, %i[ + local + master_timeout + cluster_manager_timeout + flat_settings + wait_for_metadata_version + wait_for_timeout + ignore_unavailable + allow_no_indices + expand_wildcards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/cluster/stats.rb b/opensearch-api/lib/opensearch/api/actions/cluster/stats.rb index ab0f38e0b..4302abb78 100644 --- a/opensearch-api/lib/opensearch/api/actions/cluster/stats.rb +++ b/opensearch-api/lib/opensearch/api/actions/cluster/stats.rb @@ -47,7 +47,7 @@ def stats(arguments = {}) path = if _node_id "_cluster/stats/nodes/#{Utils.__listify(_node_id)}" else - "_cluster/stats" + '_cluster/stats' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -58,9 +58,9 @@ def stats(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:stats, [ - :flat_settings, - :timeout + ParamsRegistry.register(:stats, %i[ + flat_settings + timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/count.rb b/opensearch-api/lib/opensearch/api/actions/count.rb index e20e57e1a..64707b483 100644 --- a/opensearch-api/lib/opensearch/api/actions/count.rb +++ b/opensearch-api/lib/opensearch/api/actions/count.rb @@ -64,7 +64,7 @@ def count(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_count" else - "_count" + '_count' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -75,21 +75,21 @@ def count(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:count, [ - :ignore_unavailable, - :ignore_throttled, - :allow_no_indices, - :expand_wildcards, - :min_score, - :preference, - :routing, - :q, - :analyzer, - :analyze_wildcard, - :default_operator, - :df, - :lenient, - :terminate_after + ParamsRegistry.register(:count, %i[ + ignore_unavailable + ignore_throttled + allow_no_indices + expand_wildcards + min_score + preference + routing + q + analyzer + analyze_wildcard + default_operator + df + lenient + terminate_after ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/create_pit.rb b/opensearch-api/lib/opensearch/api/actions/create_pit.rb index 2822805c8..2d95f565f 100644 --- a/opensearch-api/lib/opensearch/api/actions/create_pit.rb +++ b/opensearch-api/lib/opensearch/api/actions/create_pit.rb @@ -33,12 +33,12 @@ def create_pit(arguments = {}) perform_request(method, path, params, body).body end - ParamsRegistry.register(:create_pit, [ - :keep_alive, - :preference, - :routing, - :expand_wildcards, - :allow_partial_pit_creation + ParamsRegistry.register(:create_pit, %i[ + keep_alive + preference + routing + expand_wildcards + allow_partial_pit_creation ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/dangling_indices/delete_dangling_index.rb b/opensearch-api/lib/opensearch/api/actions/dangling_indices/delete_dangling_index.rb index e5c2adf51..787d67a39 100644 --- a/opensearch-api/lib/opensearch/api/actions/dangling_indices/delete_dangling_index.rb +++ b/opensearch-api/lib/opensearch/api/actions/dangling_indices/delete_dangling_index.rb @@ -58,11 +58,11 @@ def delete_dangling_index(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:delete_dangling_index, [ - :accept_data_loss, - :timeout, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:delete_dangling_index, %i[ + accept_data_loss + timeout + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/dangling_indices/import_dangling_index.rb b/opensearch-api/lib/opensearch/api/actions/dangling_indices/import_dangling_index.rb index 23761f904..71015298b 100644 --- a/opensearch-api/lib/opensearch/api/actions/dangling_indices/import_dangling_index.rb +++ b/opensearch-api/lib/opensearch/api/actions/dangling_indices/import_dangling_index.rb @@ -57,11 +57,11 @@ def import_dangling_index(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:import_dangling_index, [ - :accept_data_loss, - :timeout, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:import_dangling_index, %i[ + accept_data_loss + timeout + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/dangling_indices/list_dangling_indices.rb b/opensearch-api/lib/opensearch/api/actions/dangling_indices/list_dangling_indices.rb index 4730b1f89..5d2048a0f 100644 --- a/opensearch-api/lib/opensearch/api/actions/dangling_indices/list_dangling_indices.rb +++ b/opensearch-api/lib/opensearch/api/actions/dangling_indices/list_dangling_indices.rb @@ -39,7 +39,7 @@ def list_dangling_indices(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_dangling" + path = '_dangling' params = {} body = nil diff --git a/opensearch-api/lib/opensearch/api/actions/delete.rb b/opensearch-api/lib/opensearch/api/actions/delete.rb index 358d1dc2e..69baf282a 100644 --- a/opensearch-api/lib/opensearch/api/actions/delete.rb +++ b/opensearch-api/lib/opensearch/api/actions/delete.rb @@ -74,15 +74,15 @@ def delete(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:delete, [ - :wait_for_active_shards, - :refresh, - :routing, - :timeout, - :if_seq_no, - :if_primary_term, - :version, - :version_type + ParamsRegistry.register(:delete, %i[ + wait_for_active_shards + refresh + routing + timeout + if_seq_no + if_primary_term + version + version_type ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/delete_all_pits.rb b/opensearch-api/lib/opensearch/api/actions/delete_all_pits.rb index 8a54084a5..2bdbe0509 100644 --- a/opensearch-api/lib/opensearch/api/actions/delete_all_pits.rb +++ b/opensearch-api/lib/opensearch/api/actions/delete_all_pits.rb @@ -13,7 +13,7 @@ module Actions # Deletes all PITs. def delete_all_pits(arguments = {}) method = OpenSearch::API::HTTP_DELETE - path = "_search/point_in_time/_all" + path = '_search/point_in_time/_all' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil diff --git a/opensearch-api/lib/opensearch/api/actions/delete_by_query.rb b/opensearch-api/lib/opensearch/api/actions/delete_by_query.rb index 7ebe09c23..d9c792fb9 100644 --- a/opensearch-api/lib/opensearch/api/actions/delete_by_query.rb +++ b/opensearch-api/lib/opensearch/api/actions/delete_by_query.rb @@ -93,40 +93,40 @@ def delete_by_query(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:delete_by_query, [ - :analyzer, - :analyze_wildcard, - :default_operator, - :df, - :from, - :ignore_unavailable, - :allow_no_indices, - :conflicts, - :expand_wildcards, - :lenient, - :preference, - :q, - :routing, - :scroll, - :search_type, - :search_timeout, - :size, - :max_docs, - :sort, - :_source, - :_source_excludes, - :_source_includes, - :terminate_after, - :stats, - :version, - :request_cache, - :refresh, - :timeout, - :wait_for_active_shards, - :scroll_size, - :wait_for_completion, - :requests_per_second, - :slices + ParamsRegistry.register(:delete_by_query, %i[ + analyzer + analyze_wildcard + default_operator + df + from + ignore_unavailable + allow_no_indices + conflicts + expand_wildcards + lenient + preference + q + routing + scroll + search_type + search_timeout + size + max_docs + sort + _source + _source_excludes + _source_includes + terminate_after + stats + version + request_cache + refresh + timeout + wait_for_active_shards + scroll_size + wait_for_completion + requests_per_second + slices ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/delete_pit.rb b/opensearch-api/lib/opensearch/api/actions/delete_pit.rb index 19c15ffa6..35cc8684c 100644 --- a/opensearch-api/lib/opensearch/api/actions/delete_pit.rb +++ b/opensearch-api/lib/opensearch/api/actions/delete_pit.rb @@ -17,7 +17,7 @@ def delete_pit(arguments = {}) raise ArgumentError, "Required argument 'body' missing" unless arguments[:body] method = OpenSearch::API::HTTP_DELETE - path = "_search/point_in_time" + path = '_search/point_in_time' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] diff --git a/opensearch-api/lib/opensearch/api/actions/delete_script.rb b/opensearch-api/lib/opensearch/api/actions/delete_script.rb index 15fd9a9fd..de86e7b6c 100644 --- a/opensearch-api/lib/opensearch/api/actions/delete_script.rb +++ b/opensearch-api/lib/opensearch/api/actions/delete_script.rb @@ -31,7 +31,7 @@ module Actions # # @option arguments [String] :id Script ID # @option arguments [Time] :timeout Explicit operation timeout - # @option arguments [Time] :master_timeout (DEPRECATED: use cluster_manager_timeout instead) Specify timeout for connection to master + # @option arguments [Time] :master_timeout (DEPRECATED: use cluster_manager_timeout instead) Specify timeout for connection to master # @option arguments [Time] :cluster_manager_timeout Specify timeout for connection to cluster_manager # @option arguments [Hash] :headers Custom HTTP headers # @@ -56,10 +56,10 @@ def delete_script(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:delete_script, [ - :timeout, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:delete_script, %i[ + timeout + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/exists.rb b/opensearch-api/lib/opensearch/api/actions/exists.rb index 21acb5be5..e9123193f 100644 --- a/opensearch-api/lib/opensearch/api/actions/exists.rb +++ b/opensearch-api/lib/opensearch/api/actions/exists.rb @@ -68,26 +68,26 @@ def exists(arguments = {}) body = nil Utils.__rescue_from_not_found do - perform_request(method, path, params, body, headers).status == 200 ? true : false + perform_request(method, path, params, body, headers).status == 200 end end - alias_method :exists?, :exists + alias exists? exists # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:exists, [ - :stored_fields, - :preference, - :realtime, - :refresh, - :routing, - :_source, - :_source_excludes, - :_source_includes, - :version, - :version_type + ParamsRegistry.register(:exists, %i[ + stored_fields + preference + realtime + refresh + routing + _source + _source_excludes + _source_includes + version + version_type ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/exists_source.rb b/opensearch-api/lib/opensearch/api/actions/exists_source.rb index 4259780e7..c4e1f5c4e 100644 --- a/opensearch-api/lib/opensearch/api/actions/exists_source.rb +++ b/opensearch-api/lib/opensearch/api/actions/exists_source.rb @@ -68,21 +68,21 @@ def exists_source(arguments = {}) perform_request(method, path, params, body, headers).body end - alias_method :exists_source?, :exists_source + alias exists_source? exists_source # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:exists_source, [ - :preference, - :realtime, - :refresh, - :routing, - :_source, - :_source_excludes, - :_source_includes, - :version, - :version_type + ParamsRegistry.register(:exists_source, %i[ + preference + realtime + refresh + routing + _source + _source_excludes + _source_includes + version + version_type ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/explain.rb b/opensearch-api/lib/opensearch/api/actions/explain.rb index cc32bd5e9..c42ed2a86 100644 --- a/opensearch-api/lib/opensearch/api/actions/explain.rb +++ b/opensearch-api/lib/opensearch/api/actions/explain.rb @@ -80,19 +80,19 @@ def explain(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:explain, [ - :analyze_wildcard, - :analyzer, - :default_operator, - :df, - :stored_fields, - :lenient, - :preference, - :q, - :routing, - :_source, - :_source_excludes, - :_source_includes + ParamsRegistry.register(:explain, %i[ + analyze_wildcard + analyzer + default_operator + df + stored_fields + lenient + preference + q + routing + _source + _source_excludes + _source_includes ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/features/get_features.rb b/opensearch-api/lib/opensearch/api/actions/features/get_features.rb index ce2955632..63e22b85e 100644 --- a/opensearch-api/lib/opensearch/api/actions/features/get_features.rb +++ b/opensearch-api/lib/opensearch/api/actions/features/get_features.rb @@ -41,7 +41,7 @@ def get_features(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_features" + path = '_features' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil @@ -51,9 +51,9 @@ def get_features(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get_features, [ - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:get_features, %i[ + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/features/reset_features.rb b/opensearch-api/lib/opensearch/api/actions/features/reset_features.rb index e46d7fafb..0369a62dd 100644 --- a/opensearch-api/lib/opensearch/api/actions/features/reset_features.rb +++ b/opensearch-api/lib/opensearch/api/actions/features/reset_features.rb @@ -43,7 +43,7 @@ def reset_features(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_POST - path = "_features/_reset" + path = '_features/_reset' params = {} body = nil diff --git a/opensearch-api/lib/opensearch/api/actions/field_caps.rb b/opensearch-api/lib/opensearch/api/actions/field_caps.rb index 7b4b9f780..4c2f46790 100644 --- a/opensearch-api/lib/opensearch/api/actions/field_caps.rb +++ b/opensearch-api/lib/opensearch/api/actions/field_caps.rb @@ -55,7 +55,7 @@ def field_caps(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_field_caps" else - "_field_caps" + '_field_caps' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -66,12 +66,12 @@ def field_caps(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:field_caps, [ - :fields, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :include_unmapped + ParamsRegistry.register(:field_caps, %i[ + fields + ignore_unavailable + allow_no_indices + expand_wildcards + include_unmapped ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/get.rb b/opensearch-api/lib/opensearch/api/actions/get.rb index 1271c9fb6..00dcb6bed 100644 --- a/opensearch-api/lib/opensearch/api/actions/get.rb +++ b/opensearch-api/lib/opensearch/api/actions/get.rb @@ -76,17 +76,17 @@ def get(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get, [ - :stored_fields, - :preference, - :realtime, - :refresh, - :routing, - :_source, - :_source_excludes, - :_source_includes, - :version, - :version_type + ParamsRegistry.register(:get, %i[ + stored_fields + preference + realtime + refresh + routing + _source + _source_excludes + _source_includes + version + version_type ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/get_all_pits.rb b/opensearch-api/lib/opensearch/api/actions/get_all_pits.rb index f4cda7f20..47e83c4ed 100644 --- a/opensearch-api/lib/opensearch/api/actions/get_all_pits.rb +++ b/opensearch-api/lib/opensearch/api/actions/get_all_pits.rb @@ -13,7 +13,7 @@ module Actions # Gets all PITs. def get_all_pits(arguments = {}) method = OpenSearch::API::HTTP_GET - path = "_search/point_in_time/_all" + path = '_search/point_in_time/_all' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil diff --git a/opensearch-api/lib/opensearch/api/actions/get_script.rb b/opensearch-api/lib/opensearch/api/actions/get_script.rb index aae8b672d..72aa4157d 100644 --- a/opensearch-api/lib/opensearch/api/actions/get_script.rb +++ b/opensearch-api/lib/opensearch/api/actions/get_script.rb @@ -55,9 +55,9 @@ def get_script(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get_script, [ - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:get_script, %i[ + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/get_script_context.rb b/opensearch-api/lib/opensearch/api/actions/get_script_context.rb index bfc6f8a8b..cf4b38d51 100644 --- a/opensearch-api/lib/opensearch/api/actions/get_script_context.rb +++ b/opensearch-api/lib/opensearch/api/actions/get_script_context.rb @@ -42,7 +42,7 @@ def get_script_context(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_script_context" + path = '_script_context' params = {} body = nil diff --git a/opensearch-api/lib/opensearch/api/actions/get_script_languages.rb b/opensearch-api/lib/opensearch/api/actions/get_script_languages.rb index 4a37303f8..ace30d290 100644 --- a/opensearch-api/lib/opensearch/api/actions/get_script_languages.rb +++ b/opensearch-api/lib/opensearch/api/actions/get_script_languages.rb @@ -42,7 +42,7 @@ def get_script_languages(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_script_language" + path = '_script_language' params = {} body = nil diff --git a/opensearch-api/lib/opensearch/api/actions/get_source.rb b/opensearch-api/lib/opensearch/api/actions/get_source.rb index 9f9ab84c7..c6a205377 100644 --- a/opensearch-api/lib/opensearch/api/actions/get_source.rb +++ b/opensearch-api/lib/opensearch/api/actions/get_source.rb @@ -71,16 +71,16 @@ def get_source(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get_source, [ - :preference, - :realtime, - :refresh, - :routing, - :_source, - :_source_excludes, - :_source_includes, - :version, - :version_type + ParamsRegistry.register(:get_source, %i[ + preference + realtime + refresh + routing + _source + _source_excludes + _source_includes + version + version_type ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/index.rb b/opensearch-api/lib/opensearch/api/actions/index.rb index 82059bd3d..c482afbb4 100644 --- a/opensearch-api/lib/opensearch/api/actions/index.rb +++ b/opensearch-api/lib/opensearch/api/actions/index.rb @@ -78,18 +78,18 @@ def index(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:index, [ - :wait_for_active_shards, - :op_type, - :refresh, - :routing, - :timeout, - :version, - :version_type, - :if_seq_no, - :if_primary_term, - :pipeline, - :require_alias + ParamsRegistry.register(:index, %i[ + wait_for_active_shards + op_type + refresh + routing + timeout + version + version_type + if_seq_no + if_primary_term + pipeline + require_alias ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/add_block.rb b/opensearch-api/lib/opensearch/api/actions/indices/add_block.rb index 153f33e00..6510b0e52 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/add_block.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/add_block.rb @@ -64,13 +64,13 @@ def add_block(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:add_block, [ - :timeout, - :master_timeout, - :cluster_manager_timeout, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards + ParamsRegistry.register(:add_block, %i[ + timeout + master_timeout + cluster_manager_timeout + ignore_unavailable + allow_no_indices + expand_wildcards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/analyze.rb b/opensearch-api/lib/opensearch/api/actions/indices/analyze.rb index 61a49a61c..d95cbd919 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/analyze.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/analyze.rb @@ -51,7 +51,7 @@ def analyze(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_analyze" else - "_analyze" + '_analyze' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) diff --git a/opensearch-api/lib/opensearch/api/actions/indices/clear_cache.rb b/opensearch-api/lib/opensearch/api/actions/indices/clear_cache.rb index 509577325..1aebd0771 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/clear_cache.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/clear_cache.rb @@ -52,7 +52,7 @@ def clear_cache(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_cache/clear" else - "_cache/clear" + '_cache/clear' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -63,15 +63,15 @@ def clear_cache(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:clear_cache, [ - :fielddata, - :fields, - :query, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :index, - :request + ParamsRegistry.register(:clear_cache, %i[ + fielddata + fields + query + ignore_unavailable + allow_no_indices + expand_wildcards + index + request ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/clone.rb b/opensearch-api/lib/opensearch/api/actions/indices/clone.rb index a770dae79..b28c97a66 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/clone.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/clone.rb @@ -63,11 +63,11 @@ def clone(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:clone, [ - :timeout, - :master_timeout, - :cluster_manager_timeout, - :wait_for_active_shards + ParamsRegistry.register(:clone, %i[ + timeout + master_timeout + cluster_manager_timeout + wait_for_active_shards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/close.rb b/opensearch-api/lib/opensearch/api/actions/indices/close.rb index 7b0d7bb87..66b892e60 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/close.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/close.rb @@ -61,14 +61,14 @@ def close(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:close, [ - :timeout, - :master_timeout, - :cluster_manager_timeout, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :wait_for_active_shards + ParamsRegistry.register(:close, %i[ + timeout + master_timeout + cluster_manager_timeout + ignore_unavailable + allow_no_indices + expand_wildcards + wait_for_active_shards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/create.rb b/opensearch-api/lib/opensearch/api/actions/indices/create.rb index f934e99e2..41d05841f 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/create.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/create.rb @@ -49,7 +49,7 @@ def create(arguments = {}) _index = arguments.delete(:index) method = OpenSearch::API::HTTP_PUT - path = "#{Utils.__listify(_index)}" + path = Utils.__listify(_index).to_s params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] @@ -59,11 +59,11 @@ def create(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:create, [ - :wait_for_active_shards, - :timeout, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:create, %i[ + wait_for_active_shards + timeout + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/delete.rb b/opensearch-api/lib/opensearch/api/actions/indices/delete.rb index db72a0543..2110934b5 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/delete.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/delete.rb @@ -50,7 +50,7 @@ def delete(arguments = {}) _index = arguments.delete(:index) method = OpenSearch::API::HTTP_DELETE - path = "#{Utils.__listify(_index)}" + path = Utils.__listify(_index).to_s params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil @@ -64,13 +64,13 @@ def delete(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:delete, [ - :timeout, - :master_timeout, - :cluster_manager_timeout, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards + ParamsRegistry.register(:delete, %i[ + timeout + master_timeout + cluster_manager_timeout + ignore_unavailable + allow_no_indices + expand_wildcards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/delete_alias.rb b/opensearch-api/lib/opensearch/api/actions/indices/delete_alias.rb index eeb03ce3a..44762e614 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/delete_alias.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/delete_alias.rb @@ -51,9 +51,7 @@ def delete_alias(arguments = {}) _name = arguments.delete(:name) method = OpenSearch::API::HTTP_DELETE - path = if _index && _name - "#{Utils.__listify(_index)}/_aliases/#{Utils.__listify(_name)}" - end + path = ("#{Utils.__listify(_index)}/_aliases/#{Utils.__listify(_name)}" if _index && _name) params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil @@ -63,10 +61,10 @@ def delete_alias(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:delete_alias, [ - :timeout, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:delete_alias, %i[ + timeout + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/delete_index_template.rb b/opensearch-api/lib/opensearch/api/actions/indices/delete_index_template.rb index 230a9e0fe..c08517a07 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/delete_index_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/delete_index_template.rb @@ -57,10 +57,10 @@ def delete_index_template(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:delete_index_template, [ - :timeout, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:delete_index_template, %i[ + timeout + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/delete_template.rb b/opensearch-api/lib/opensearch/api/actions/indices/delete_template.rb index ac29dcaa5..a4e0fb42b 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/delete_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/delete_template.rb @@ -61,10 +61,10 @@ def delete_template(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:delete_template, [ - :timeout, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:delete_template, %i[ + timeout + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/disk_usage.rb b/opensearch-api/lib/opensearch/api/actions/indices/disk_usage.rb index 520c4d05a..729f42a17 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/disk_usage.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/disk_usage.rb @@ -63,12 +63,12 @@ def disk_usage(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:disk_usage, [ - :run_expensive_tasks, - :flush, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards + ParamsRegistry.register(:disk_usage, %i[ + run_expensive_tasks + flush + ignore_unavailable + allow_no_indices + expand_wildcards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/exists.rb b/opensearch-api/lib/opensearch/api/actions/indices/exists.rb index 701ddd84c..844eacd04 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/exists.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/exists.rb @@ -50,28 +50,28 @@ def exists(arguments = {}) _index = arguments.delete(:index) method = OpenSearch::API::HTTP_HEAD - path = "#{Utils.__listify(_index)}" + path = Utils.__listify(_index).to_s params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil Utils.__rescue_from_not_found do - perform_request(method, path, params, body, headers).status == 200 ? true : false + perform_request(method, path, params, body, headers).status == 200 end end - alias_method :exists?, :exists + alias exists? exists # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:exists, [ - :local, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :flat_settings, - :include_defaults + ParamsRegistry.register(:exists, %i[ + local + ignore_unavailable + allow_no_indices + expand_wildcards + flat_settings + include_defaults ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/exists_alias.rb b/opensearch-api/lib/opensearch/api/actions/indices/exists_alias.rb index 3bc4e7944..7af1de652 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/exists_alias.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/exists_alias.rb @@ -61,20 +61,20 @@ def exists_alias(arguments = {}) body = nil Utils.__rescue_from_not_found do - perform_request(method, path, params, body, headers).status == 200 ? true : false + perform_request(method, path, params, body, headers).status == 200 end end - alias_method :exists_alias?, :exists_alias + alias exists_alias? exists_alias # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:exists_alias, [ - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :local + ParamsRegistry.register(:exists_alias, %i[ + ignore_unavailable + allow_no_indices + expand_wildcards + local ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/exists_index_template.rb b/opensearch-api/lib/opensearch/api/actions/indices/exists_index_template.rb index 7012c27e7..fff274d67 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/exists_index_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/exists_index_template.rb @@ -55,16 +55,16 @@ def exists_index_template(arguments = {}) perform_request(method, path, params, body, headers).body end - alias_method :exists_index_template?, :exists_index_template + alias exists_index_template? exists_index_template # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:exists_index_template, [ - :flat_settings, - :master_timeout, - :cluster_manager_timeout, - :local + ParamsRegistry.register(:exists_index_template, %i[ + flat_settings + master_timeout + cluster_manager_timeout + local ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/exists_template.rb b/opensearch-api/lib/opensearch/api/actions/indices/exists_template.rb index 524cbf85f..2250ec355 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/exists_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/exists_template.rb @@ -54,20 +54,20 @@ def exists_template(arguments = {}) body = nil Utils.__rescue_from_not_found do - perform_request(method, path, params, body, headers).status == 200 ? true : false + perform_request(method, path, params, body, headers).status == 200 end end - alias_method :exists_template?, :exists_template + alias exists_template? exists_template # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:exists_template, [ - :flat_settings, - :master_timeout, - :cluster_manager_timeout, - :local + ParamsRegistry.register(:exists_template, %i[ + flat_settings + master_timeout + cluster_manager_timeout + local ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/field_usage_stats.rb b/opensearch-api/lib/opensearch/api/actions/indices/field_usage_stats.rb index a8e85ab76..3116001c4 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/field_usage_stats.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/field_usage_stats.rb @@ -62,11 +62,11 @@ def field_usage_stats(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:field_usage_stats, [ - :fields, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards + ParamsRegistry.register(:field_usage_stats, %i[ + fields + ignore_unavailable + allow_no_indices + expand_wildcards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/flush.rb b/opensearch-api/lib/opensearch/api/actions/indices/flush.rb index b84c348a0..48b6603d2 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/flush.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/flush.rb @@ -50,7 +50,7 @@ def flush(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_flush" else - "_flush" + '_flush' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -61,12 +61,12 @@ def flush(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:flush, [ - :force, - :wait_if_ongoing, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards + ParamsRegistry.register(:flush, %i[ + force + wait_if_ongoing + ignore_unavailable + allow_no_indices + expand_wildcards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/forcemerge.rb b/opensearch-api/lib/opensearch/api/actions/indices/forcemerge.rb index 1dd34648e..83ebfff50 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/forcemerge.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/forcemerge.rb @@ -51,7 +51,7 @@ def forcemerge(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_forcemerge" else - "_forcemerge" + '_forcemerge' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -62,13 +62,13 @@ def forcemerge(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:forcemerge, [ - :flush, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :max_num_segments, - :only_expunge_deletes + ParamsRegistry.register(:forcemerge, %i[ + flush + ignore_unavailable + allow_no_indices + expand_wildcards + max_num_segments + only_expunge_deletes ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/get.rb b/opensearch-api/lib/opensearch/api/actions/indices/get.rb index 5d1e993c7..1c147ced2 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/get.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/get.rb @@ -52,7 +52,7 @@ def get(arguments = {}) _index = arguments.delete(:index) method = OpenSearch::API::HTTP_GET - path = "#{Utils.__listify(_index)}" + path = Utils.__listify(_index).to_s params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil @@ -62,15 +62,15 @@ def get(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get, [ - :local, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :flat_settings, - :include_defaults, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:get, %i[ + local + ignore_unavailable + allow_no_indices + expand_wildcards + flat_settings + include_defaults + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/get_alias.rb b/opensearch-api/lib/opensearch/api/actions/indices/get_alias.rb index 2043c65ec..49edd5372 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/get_alias.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/get_alias.rb @@ -56,7 +56,7 @@ def get_alias(arguments = {}) elsif _name "_alias/#{Utils.__listify(_name)}" else - "_alias" + '_alias' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -67,11 +67,11 @@ def get_alias(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get_alias, [ - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :local + ParamsRegistry.register(:get_alias, %i[ + ignore_unavailable + allow_no_indices + expand_wildcards + local ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/get_field_mapping.rb b/opensearch-api/lib/opensearch/api/actions/indices/get_field_mapping.rb index 9653f2a0c..b263a4452 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/get_field_mapping.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/get_field_mapping.rb @@ -70,12 +70,12 @@ def get_field_mapping(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get_field_mapping, [ - :include_defaults, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :local + ParamsRegistry.register(:get_field_mapping, %i[ + include_defaults + ignore_unavailable + allow_no_indices + expand_wildcards + local ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/get_index_template.rb b/opensearch-api/lib/opensearch/api/actions/indices/get_index_template.rb index b3062d931..f735d59cf 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/get_index_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/get_index_template.rb @@ -49,7 +49,7 @@ def get_index_template(arguments = {}) path = if _name "_index_template/#{Utils.__listify(_name)}" else - "_index_template" + '_index_template' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -60,11 +60,11 @@ def get_index_template(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get_index_template, [ - :flat_settings, - :master_timeout, - :cluster_manager_timeout, - :local + ParamsRegistry.register(:get_index_template, %i[ + flat_settings + master_timeout + cluster_manager_timeout + local ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/get_mapping.rb b/opensearch-api/lib/opensearch/api/actions/indices/get_mapping.rb index 91a1c27d4..da1633d54 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/get_mapping.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/get_mapping.rb @@ -56,7 +56,7 @@ def get_mapping(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_mapping" else - "_mapping" + '_mapping' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -67,13 +67,13 @@ def get_mapping(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get_mapping, [ - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :master_timeout, - :cluster_manager_timeout, - :local + ParamsRegistry.register(:get_mapping, %i[ + ignore_unavailable + allow_no_indices + expand_wildcards + master_timeout + cluster_manager_timeout + local ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/get_settings.rb b/opensearch-api/lib/opensearch/api/actions/indices/get_settings.rb index 12a9e4a8c..8bd90d91d 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/get_settings.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/get_settings.rb @@ -60,7 +60,7 @@ def get_settings(arguments = {}) elsif _name "_settings/#{Utils.__listify(_name)}" else - "_settings" + '_settings' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -71,15 +71,15 @@ def get_settings(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get_settings, [ - :master_timeout, - :cluster_manager_timeout, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :flat_settings, - :local, - :include_defaults + ParamsRegistry.register(:get_settings, %i[ + master_timeout + cluster_manager_timeout + ignore_unavailable + allow_no_indices + expand_wildcards + flat_settings + local + include_defaults ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/get_template.rb b/opensearch-api/lib/opensearch/api/actions/indices/get_template.rb index 4c030d2e3..ce6c6e6d1 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/get_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/get_template.rb @@ -49,7 +49,7 @@ def get_template(arguments = {}) path = if _name "_template/#{Utils.__listify(_name)}" else - "_template" + '_template' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -60,11 +60,11 @@ def get_template(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get_template, [ - :flat_settings, - :master_timeout, - :cluster_manager_timeout, - :local + ParamsRegistry.register(:get_template, %i[ + flat_settings + master_timeout + cluster_manager_timeout + local ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/get_upgrade.rb b/opensearch-api/lib/opensearch/api/actions/indices/get_upgrade.rb index 84745442f..89d249d69 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/get_upgrade.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/get_upgrade.rb @@ -53,7 +53,7 @@ def get_upgrade(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_upgrade" else - "_upgrade" + '_upgrade' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -64,10 +64,10 @@ def get_upgrade(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get_upgrade, [ - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards + ParamsRegistry.register(:get_upgrade, %i[ + ignore_unavailable + allow_no_indices + expand_wildcards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/open.rb b/opensearch-api/lib/opensearch/api/actions/indices/open.rb index 006f013c4..0b61d52e5 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/open.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/open.rb @@ -61,14 +61,14 @@ def open(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:open, [ - :timeout, - :master_timeout, - :cluster_manager_timeout, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :wait_for_active_shards + ParamsRegistry.register(:open, %i[ + timeout + master_timeout + cluster_manager_timeout + ignore_unavailable + allow_no_indices + expand_wildcards + wait_for_active_shards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/put_alias.rb b/opensearch-api/lib/opensearch/api/actions/indices/put_alias.rb index 398ca166a..16581c305 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/put_alias.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/put_alias.rb @@ -52,9 +52,7 @@ def put_alias(arguments = {}) _name = arguments.delete(:name) method = OpenSearch::API::HTTP_PUT - path = if _index && _name - "#{Utils.__listify(_index)}/_aliases/#{Utils.__listify(_name)}" - end + path = ("#{Utils.__listify(_index)}/_aliases/#{Utils.__listify(_name)}" if _index && _name) params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] @@ -64,10 +62,10 @@ def put_alias(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:put_alias, [ - :timeout, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:put_alias, %i[ + timeout + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/put_index_template.rb b/opensearch-api/lib/opensearch/api/actions/indices/put_index_template.rb index 86428bdfa..69ce5dd09 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/put_index_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/put_index_template.rb @@ -60,11 +60,11 @@ def put_index_template(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:put_index_template, [ - :create, - :cause, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:put_index_template, %i[ + create + cause + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/put_mapping.rb b/opensearch-api/lib/opensearch/api/actions/indices/put_mapping.rb index 53e4621eb..fbe555ebd 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/put_mapping.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/put_mapping.rb @@ -67,14 +67,14 @@ def put_mapping(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:put_mapping, [ - :timeout, - :master_timeout, - :cluster_manager_timeout, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :write_index_only + ParamsRegistry.register(:put_mapping, %i[ + timeout + master_timeout + cluster_manager_timeout + ignore_unavailable + allow_no_indices + expand_wildcards + write_index_only ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/put_settings.rb b/opensearch-api/lib/opensearch/api/actions/indices/put_settings.rb index e80d450e9..ab5047704 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/put_settings.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/put_settings.rb @@ -56,7 +56,7 @@ def put_settings(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_settings" else - "_settings" + '_settings' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -67,15 +67,15 @@ def put_settings(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:put_settings, [ - :master_timeout, - :cluster_manager_timeout, - :timeout, - :preserve_existing, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :flat_settings + ParamsRegistry.register(:put_settings, %i[ + master_timeout + cluster_manager_timeout + timeout + preserve_existing + ignore_unavailable + allow_no_indices + expand_wildcards + flat_settings ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/put_template.rb b/opensearch-api/lib/opensearch/api/actions/indices/put_template.rb index eb8440a7a..9c3b091d8 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/put_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/put_template.rb @@ -60,11 +60,11 @@ def put_template(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:put_template, [ - :order, - :create, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:put_template, %i[ + order + create + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/recovery.rb b/opensearch-api/lib/opensearch/api/actions/indices/recovery.rb index 041bf5722..dae9dcd8c 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/recovery.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/recovery.rb @@ -47,7 +47,7 @@ def recovery(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_recovery" else - "_recovery" + '_recovery' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -58,9 +58,9 @@ def recovery(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:recovery, [ - :detailed, - :active_only + ParamsRegistry.register(:recovery, %i[ + detailed + active_only ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/refresh.rb b/opensearch-api/lib/opensearch/api/actions/indices/refresh.rb index ca687ccb4..a94156497 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/refresh.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/refresh.rb @@ -48,7 +48,7 @@ def refresh(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_refresh" else - "_refresh" + '_refresh' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -59,10 +59,10 @@ def refresh(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:refresh, [ - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards + ParamsRegistry.register(:refresh, %i[ + ignore_unavailable + allow_no_indices + expand_wildcards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/rollover.rb b/opensearch-api/lib/opensearch/api/actions/indices/rollover.rb index e8561b534..937bdc9a5 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/rollover.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/rollover.rb @@ -68,12 +68,12 @@ def rollover(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:rollover, [ - :timeout, - :dry_run, - :master_timeout, - :cluster_manager_timeout, - :wait_for_active_shards + ParamsRegistry.register(:rollover, %i[ + timeout + dry_run + master_timeout + cluster_manager_timeout + wait_for_active_shards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/segments.rb b/opensearch-api/lib/opensearch/api/actions/indices/segments.rb index 99890ea18..4f60577ac 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/segments.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/segments.rb @@ -49,7 +49,7 @@ def segments(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_segments" else - "_segments" + '_segments' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -60,11 +60,11 @@ def segments(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:segments, [ - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :verbose + ParamsRegistry.register(:segments, %i[ + ignore_unavailable + allow_no_indices + expand_wildcards + verbose ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/shard_stores.rb b/opensearch-api/lib/opensearch/api/actions/indices/shard_stores.rb index 11add16e8..225936a68 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/shard_stores.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/shard_stores.rb @@ -49,7 +49,7 @@ def shard_stores(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_shard_stores" else - "_shard_stores" + '_shard_stores' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -60,11 +60,11 @@ def shard_stores(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:shard_stores, [ - :status, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards + ParamsRegistry.register(:shard_stores, %i[ + status + ignore_unavailable + allow_no_indices + expand_wildcards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/shrink.rb b/opensearch-api/lib/opensearch/api/actions/indices/shrink.rb index 6aaa8f6c4..75d5a0f3b 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/shrink.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/shrink.rb @@ -64,12 +64,12 @@ def shrink(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:shrink, [ - :copy_settings, - :timeout, - :master_timeout, - :cluster_manager_timeout, - :wait_for_active_shards + ParamsRegistry.register(:shrink, %i[ + copy_settings + timeout + master_timeout + cluster_manager_timeout + wait_for_active_shards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/simulate_index_template.rb b/opensearch-api/lib/opensearch/api/actions/indices/simulate_index_template.rb index 03f4c5561..fb3a77c71 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/simulate_index_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/simulate_index_template.rb @@ -59,11 +59,11 @@ def simulate_index_template(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:simulate_index_template, [ - :create, - :cause, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:simulate_index_template, %i[ + create + cause + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/simulate_template.rb b/opensearch-api/lib/opensearch/api/actions/indices/simulate_template.rb index 7a3bc01c0..44727e555 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/simulate_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/simulate_template.rb @@ -50,7 +50,7 @@ def simulate_template(arguments = {}) path = if _name "_index_template/_simulate/#{Utils.__listify(_name)}" else - "_index_template/_simulate" + '_index_template/_simulate' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -61,11 +61,11 @@ def simulate_template(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:simulate_template, [ - :create, - :cause, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:simulate_template, %i[ + create + cause + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/split.rb b/opensearch-api/lib/opensearch/api/actions/indices/split.rb index 912c16561..b75cf6f22 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/split.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/split.rb @@ -64,12 +64,12 @@ def split(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:split, [ - :copy_settings, - :timeout, - :master_timeout, - :cluster_manager_timeout, - :wait_for_active_shards + ParamsRegistry.register(:split, %i[ + copy_settings + timeout + master_timeout + cluster_manager_timeout + wait_for_active_shards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/stats.rb b/opensearch-api/lib/opensearch/api/actions/indices/stats.rb index c23ea01b6..41156485c 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/stats.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/stats.rb @@ -52,8 +52,8 @@ def stats(arguments = {}) parts = Utils.__extract_parts arguments, ParamsRegistry.get(:stats_parts) path = Utils.__pathify Utils.__listify(arguments[:index]), '_stats', Utils.__listify(parts) params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(:stats_params) - params[:fields] = Utils.__listify(params[:fields], :escape => false) if params[:fields] - params[:groups] = Utils.__listify(params[:groups], :escape => false) if params[:groups] + params[:fields] = Utils.__listify(params[:fields], escape: false) if params[:fields] + params[:groups] = Utils.__listify(params[:groups], escape: false) if params[:groups] body = nil perform_request(method, path, params, body, headers).body @@ -62,37 +62,37 @@ def stats(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:stats_params, [ - :completion_fields, - :fielddata_fields, - :fields, - :groups, - :level, - :types, - :include_segment_file_sizes, - :include_unloaded_segments, - :expand_wildcards, - :forbid_closed_indices + ParamsRegistry.register(:stats_params, %i[ + completion_fields + fielddata_fields + fields + groups + level + types + include_segment_file_sizes + include_unloaded_segments + expand_wildcards + forbid_closed_indices ].freeze) - ParamsRegistry.register(:stats_parts, [ - :_all, - :completion, - :docs, - :fielddata, - :query_cache, - :flush, - :get, - :indexing, - :merge, - :request_cache, - :refresh, - :search, - :segments, - :store, - :warmer, - :suggest, - :metric + ParamsRegistry.register(:stats_parts, %i[ + _all + completion + docs + fielddata + query_cache + flush + get + indexing + merge + request_cache + refresh + search + segments + store + warmer + suggest + metric ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/update_aliases.rb b/opensearch-api/lib/opensearch/api/actions/indices/update_aliases.rb index 6e1c456c2..47b7397ff 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/update_aliases.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/update_aliases.rb @@ -45,7 +45,7 @@ def update_aliases(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_POST - path = "_aliases" + path = '_aliases' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] @@ -55,10 +55,10 @@ def update_aliases(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:update_aliases, [ - :timeout, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:update_aliases, %i[ + timeout + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/upgrade.rb b/opensearch-api/lib/opensearch/api/actions/indices/upgrade.rb index 8e8fce408..a1ac37130 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/upgrade.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/upgrade.rb @@ -55,7 +55,7 @@ def upgrade(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_upgrade" else - "_upgrade" + '_upgrade' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -66,12 +66,12 @@ def upgrade(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:upgrade, [ - :allow_no_indices, - :expand_wildcards, - :ignore_unavailable, - :wait_for_completion, - :only_ancient_segments + ParamsRegistry.register(:upgrade, %i[ + allow_no_indices + expand_wildcards + ignore_unavailable + wait_for_completion + only_ancient_segments ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/indices/validate_query.rb b/opensearch-api/lib/opensearch/api/actions/indices/validate_query.rb index 34eed0930..88525c0e9 100644 --- a/opensearch-api/lib/opensearch/api/actions/indices/validate_query.rb +++ b/opensearch-api/lib/opensearch/api/actions/indices/validate_query.rb @@ -68,7 +68,7 @@ def validate_query(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_validate/query" else - "_validate/query" + '_validate/query' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -79,19 +79,19 @@ def validate_query(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:validate_query, [ - :explain, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :q, - :analyzer, - :analyze_wildcard, - :default_operator, - :df, - :lenient, - :rewrite, - :all_shards + ParamsRegistry.register(:validate_query, %i[ + explain + ignore_unavailable + allow_no_indices + expand_wildcards + q + analyzer + analyze_wildcard + default_operator + df + lenient + rewrite + all_shards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/info.rb b/opensearch-api/lib/opensearch/api/actions/info.rb index a4128e05c..0e2190f0a 100644 --- a/opensearch-api/lib/opensearch/api/actions/info.rb +++ b/opensearch-api/lib/opensearch/api/actions/info.rb @@ -38,7 +38,7 @@ def info(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "" + path = '' params = {} body = nil diff --git a/opensearch-api/lib/opensearch/api/actions/ingest/delete_pipeline.rb b/opensearch-api/lib/opensearch/api/actions/ingest/delete_pipeline.rb index c3c9fd31e..f5bd6c852 100644 --- a/opensearch-api/lib/opensearch/api/actions/ingest/delete_pipeline.rb +++ b/opensearch-api/lib/opensearch/api/actions/ingest/delete_pipeline.rb @@ -57,10 +57,10 @@ def delete_pipeline(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:delete_pipeline, [ - :master_timeout, - :cluster_manager_timeout, - :timeout + ParamsRegistry.register(:delete_pipeline, %i[ + master_timeout + cluster_manager_timeout + timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/ingest/geo_ip_stats.rb b/opensearch-api/lib/opensearch/api/actions/ingest/geo_ip_stats.rb index 4b63dbd57..ae55c2c85 100644 --- a/opensearch-api/lib/opensearch/api/actions/ingest/geo_ip_stats.rb +++ b/opensearch-api/lib/opensearch/api/actions/ingest/geo_ip_stats.rb @@ -39,7 +39,7 @@ def geo_ip_stats(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_ingest/geoip/stats" + path = '_ingest/geoip/stats' params = {} body = nil diff --git a/opensearch-api/lib/opensearch/api/actions/ingest/get_pipeline.rb b/opensearch-api/lib/opensearch/api/actions/ingest/get_pipeline.rb index 13906b6e6..326435517 100644 --- a/opensearch-api/lib/opensearch/api/actions/ingest/get_pipeline.rb +++ b/opensearch-api/lib/opensearch/api/actions/ingest/get_pipeline.rb @@ -48,7 +48,7 @@ def get_pipeline(arguments = {}) path = if _id "_ingest/pipeline/#{Utils.__listify(_id)}" else - "_ingest/pipeline" + '_ingest/pipeline' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -59,10 +59,10 @@ def get_pipeline(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get_pipeline, [ - :summary, - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:get_pipeline, %i[ + summary + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/ingest/processor_grok.rb b/opensearch-api/lib/opensearch/api/actions/ingest/processor_grok.rb index 492f70ab1..6dd0a50b6 100644 --- a/opensearch-api/lib/opensearch/api/actions/ingest/processor_grok.rb +++ b/opensearch-api/lib/opensearch/api/actions/ingest/processor_grok.rb @@ -39,7 +39,7 @@ def processor_grok(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_ingest/processor/grok" + path = '_ingest/processor/grok' params = {} body = nil diff --git a/opensearch-api/lib/opensearch/api/actions/ingest/put_pipeline.rb b/opensearch-api/lib/opensearch/api/actions/ingest/put_pipeline.rb index a454c5d05..e336b01c3 100644 --- a/opensearch-api/lib/opensearch/api/actions/ingest/put_pipeline.rb +++ b/opensearch-api/lib/opensearch/api/actions/ingest/put_pipeline.rb @@ -59,10 +59,10 @@ def put_pipeline(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:put_pipeline, [ - :master_timeout, - :cluster_manager_timeout, - :timeout + ParamsRegistry.register(:put_pipeline, %i[ + master_timeout + cluster_manager_timeout + timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/ingest/simulate.rb b/opensearch-api/lib/opensearch/api/actions/ingest/simulate.rb index f333c79d5..7202b8b6c 100644 --- a/opensearch-api/lib/opensearch/api/actions/ingest/simulate.rb +++ b/opensearch-api/lib/opensearch/api/actions/ingest/simulate.rb @@ -49,7 +49,7 @@ def simulate(arguments = {}) path = if _id "_ingest/pipeline/#{Utils.__listify(_id)}/_simulate" else - "_ingest/pipeline/_simulate" + '_ingest/pipeline/_simulate' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) diff --git a/opensearch-api/lib/opensearch/api/actions/mget.rb b/opensearch-api/lib/opensearch/api/actions/mget.rb index e5614feef..6aca51dc1 100644 --- a/opensearch-api/lib/opensearch/api/actions/mget.rb +++ b/opensearch-api/lib/opensearch/api/actions/mget.rb @@ -60,7 +60,7 @@ def mget(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_mget" else - "_mget" + '_mget' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -71,15 +71,15 @@ def mget(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:mget, [ - :stored_fields, - :preference, - :realtime, - :refresh, - :routing, - :_source, - :_source_excludes, - :_source_includes + ParamsRegistry.register(:mget, %i[ + stored_fields + preference + realtime + refresh + routing + _source + _source_excludes + _source_includes ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/msearch.rb b/opensearch-api/lib/opensearch/api/actions/msearch.rb index 68bc480f0..6f7f3c25b 100644 --- a/opensearch-api/lib/opensearch/api/actions/msearch.rb +++ b/opensearch-api/lib/opensearch/api/actions/msearch.rb @@ -59,48 +59,46 @@ def msearch(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_msearch" else - "_msearch" + '_msearch' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] - case - when body.is_a?(Array) && body.any? { |d| d.has_key? :search } + if body.is_a?(Array) && body.any? { |d| d.has_key? :search } payload = body - .inject([]) do |sum, item| + .each_with_object([]) do |item, sum| meta = item data = meta.delete(:search) sum << meta sum << data - sum end .map { |item| OpenSearch::API.serializer.dump(item) } - payload << "" unless payload.empty? + payload << '' unless payload.empty? payload = payload.join("\n") - when body.is_a?(Array) + elsif body.is_a?(Array) payload = body.map { |d| d.is_a?(String) ? d : OpenSearch::API.serializer.dump(d) } - payload << "" unless payload.empty? + payload << '' unless payload.empty? payload = payload.join("\n") else payload = body end - headers.merge!("Content-Type" => "application/x-ndjson") + headers.merge!('Content-Type' => 'application/x-ndjson') perform_request(method, path, params, payload, headers).body end # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:msearch, [ - :search_type, - :max_concurrent_searches, - :typed_keys, - :pre_filter_shard_size, - :max_concurrent_shard_requests, - :rest_total_hits_as_int, - :ccs_minimize_roundtrips + ParamsRegistry.register(:msearch, %i[ + search_type + max_concurrent_searches + typed_keys + pre_filter_shard_size + max_concurrent_shard_requests + rest_total_hits_as_int + ccs_minimize_roundtrips ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/msearch_template.rb b/opensearch-api/lib/opensearch/api/actions/msearch_template.rb index c18a5ba54..c00b2d5b6 100644 --- a/opensearch-api/lib/opensearch/api/actions/msearch_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/msearch_template.rb @@ -57,34 +57,32 @@ def msearch_template(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_msearch/template" else - "_msearch/template" + '_msearch/template' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] - case - when body.is_a?(Array) + if body.is_a?(Array) payload = body.map { |d| d.is_a?(String) ? d : OpenSearch::API.serializer.dump(d) } - payload << "" unless payload.empty? - payload = payload.join(" -") + payload << '' unless payload.empty? + payload = payload.join("\n") else payload = body end - headers.merge!("Content-Type" => "application/x-ndjson") + headers.merge!('Content-Type' => 'application/x-ndjson') perform_request(method, path, params, payload, headers).body end # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:msearch_template, [ - :search_type, - :typed_keys, - :max_concurrent_searches, - :rest_total_hits_as_int, - :ccs_minimize_roundtrips + ParamsRegistry.register(:msearch_template, %i[ + search_type + typed_keys + max_concurrent_searches + rest_total_hits_as_int + ccs_minimize_roundtrips ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/mtermvectors.rb b/opensearch-api/lib/opensearch/api/actions/mtermvectors.rb index c4e3177f6..43149fa93 100644 --- a/opensearch-api/lib/opensearch/api/actions/mtermvectors.rb +++ b/opensearch-api/lib/opensearch/api/actions/mtermvectors.rb @@ -68,34 +68,34 @@ def mtermvectors(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_mtermvectors" else - "_mtermvectors" + '_mtermvectors' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) - if ids - body = { :ids => ids } - else - body = arguments[:body] - end + body = if ids + { ids: ids } + else + arguments[:body] + end perform_request(method, path, params, body, headers).body end # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:mtermvectors, [ - :ids, - :term_statistics, - :field_statistics, - :fields, - :offsets, - :positions, - :payloads, - :preference, - :routing, - :realtime, - :version, - :version_type + ParamsRegistry.register(:mtermvectors, %i[ + ids + term_statistics + field_statistics + fields + offsets + positions + payloads + preference + routing + realtime + version + version_type ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/nodes/hot_threads.rb b/opensearch-api/lib/opensearch/api/actions/nodes/hot_threads.rb index 9a5860f4a..23e11e862 100644 --- a/opensearch-api/lib/opensearch/api/actions/nodes/hot_threads.rb +++ b/opensearch-api/lib/opensearch/api/actions/nodes/hot_threads.rb @@ -56,7 +56,7 @@ def hot_threads(arguments = {}) path = if _node_id "_cluster/nodes/#{Utils.__listify(_node_id)}/hot_threads" else - "_cluster/nodes/hot_threads" + '_cluster/nodes/hot_threads' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -67,13 +67,13 @@ def hot_threads(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:hot_threads, [ - :interval, - :snapshots, - :threads, - :ignore_idle_threads, - :type, - :timeout + ParamsRegistry.register(:hot_threads, %i[ + interval + snapshots + threads + ignore_idle_threads + type + timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/nodes/info.rb b/opensearch-api/lib/opensearch/api/actions/nodes/info.rb index 9731f054b..3f6317247 100644 --- a/opensearch-api/lib/opensearch/api/actions/nodes/info.rb +++ b/opensearch-api/lib/opensearch/api/actions/nodes/info.rb @@ -54,7 +54,7 @@ def info(arguments = {}) elsif _metric "_nodes/#{Utils.__listify(_metric)}" else - "_nodes" + '_nodes' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -65,9 +65,9 @@ def info(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:info, [ - :flat_settings, - :timeout + ParamsRegistry.register(:info, %i[ + flat_settings + timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/nodes/reload_secure_settings.rb b/opensearch-api/lib/opensearch/api/actions/nodes/reload_secure_settings.rb index ef8482bd7..83e9809bd 100644 --- a/opensearch-api/lib/opensearch/api/actions/nodes/reload_secure_settings.rb +++ b/opensearch-api/lib/opensearch/api/actions/nodes/reload_secure_settings.rb @@ -47,7 +47,7 @@ def reload_secure_settings(arguments = {}) path = if _node_id "_nodes/#{Utils.__listify(_node_id)}/reload_secure_settings" else - "_nodes/reload_secure_settings" + '_nodes/reload_secure_settings' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) diff --git a/opensearch-api/lib/opensearch/api/actions/nodes/shutdown.rb b/opensearch-api/lib/opensearch/api/actions/nodes/shutdown.rb index 388f3fa8c..f8836aa00 100644 --- a/opensearch-api/lib/opensearch/api/actions/nodes/shutdown.rb +++ b/opensearch-api/lib/opensearch/api/actions/nodes/shutdown.rb @@ -55,9 +55,9 @@ def shutdown(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.1.1 - ParamsRegistry.register(:shutdown, [ - :delay, - :exit + ParamsRegistry.register(:shutdown, %i[ + delay + exit ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/nodes/stats.rb b/opensearch-api/lib/opensearch/api/actions/nodes/stats.rb index 91fafaa5b..6645bc1fd 100644 --- a/opensearch-api/lib/opensearch/api/actions/nodes/stats.rb +++ b/opensearch-api/lib/opensearch/api/actions/nodes/stats.rb @@ -68,7 +68,7 @@ def stats(arguments = {}) elsif _metric "_nodes/stats/#{Utils.__listify(_metric)}" else - "_nodes/stats" + '_nodes/stats' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -79,16 +79,16 @@ def stats(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:stats, [ - :completion_fields, - :fielddata_fields, - :fields, - :groups, - :level, - :types, - :timeout, - :include_segment_file_sizes, - :include_unloaded_segments + ParamsRegistry.register(:stats, %i[ + completion_fields + fielddata_fields + fields + groups + level + types + timeout + include_segment_file_sizes + include_unloaded_segments ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/nodes/usage.rb b/opensearch-api/lib/opensearch/api/actions/nodes/usage.rb index 2793fb0c7..0aa00c81e 100644 --- a/opensearch-api/lib/opensearch/api/actions/nodes/usage.rb +++ b/opensearch-api/lib/opensearch/api/actions/nodes/usage.rb @@ -53,7 +53,7 @@ def usage(arguments = {}) elsif _metric "_nodes/usage/#{Utils.__listify(_metric)}" else - "_nodes/usage" + '_nodes/usage' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) diff --git a/opensearch-api/lib/opensearch/api/actions/ping.rb b/opensearch-api/lib/opensearch/api/actions/ping.rb index a338b27f7..2134e905b 100644 --- a/opensearch-api/lib/opensearch/api/actions/ping.rb +++ b/opensearch-api/lib/opensearch/api/actions/ping.rb @@ -38,12 +38,12 @@ def ping(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_HEAD - path = "" + path = '' params = {} body = nil begin - perform_request(method, path, params, body, headers).status == 200 ? true : false + perform_request(method, path, params, body, headers).status == 200 rescue Exception => e if e.class.to_s =~ /NotFound|ConnectionFailed/ || e.message =~ /Not *Found|404|ConnectionFailed/i false diff --git a/opensearch-api/lib/opensearch/api/actions/put_script.rb b/opensearch-api/lib/opensearch/api/actions/put_script.rb index da801d641..eb48bf5f2 100644 --- a/opensearch-api/lib/opensearch/api/actions/put_script.rb +++ b/opensearch-api/lib/opensearch/api/actions/put_script.rb @@ -65,11 +65,11 @@ def put_script(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:put_script, [ - :timeout, - :master_timeout, - :cluster_manager_timeout, - :context + ParamsRegistry.register(:put_script, %i[ + timeout + master_timeout + cluster_manager_timeout + context ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/rank_eval.rb b/opensearch-api/lib/opensearch/api/actions/rank_eval.rb index 7997623e8..d5cb91ddc 100644 --- a/opensearch-api/lib/opensearch/api/actions/rank_eval.rb +++ b/opensearch-api/lib/opensearch/api/actions/rank_eval.rb @@ -55,7 +55,7 @@ def rank_eval(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_rank_eval" else - "_rank_eval" + '_rank_eval' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -66,11 +66,11 @@ def rank_eval(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:rank_eval, [ - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards, - :search_type + ParamsRegistry.register(:rank_eval, %i[ + ignore_unavailable + allow_no_indices + expand_wildcards + search_type ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/reindex.rb b/opensearch-api/lib/opensearch/api/actions/reindex.rb index ee2e159ab..bdc4a50a0 100644 --- a/opensearch-api/lib/opensearch/api/actions/reindex.rb +++ b/opensearch-api/lib/opensearch/api/actions/reindex.rb @@ -51,7 +51,7 @@ def reindex(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_POST - path = "_reindex" + path = '_reindex' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = arguments[:body] @@ -61,15 +61,15 @@ def reindex(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:reindex, [ - :refresh, - :timeout, - :wait_for_active_shards, - :wait_for_completion, - :requests_per_second, - :scroll, - :slices, - :max_docs + ParamsRegistry.register(:reindex, %i[ + refresh + timeout + wait_for_active_shards + wait_for_completion + requests_per_second + scroll + slices + max_docs ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/remote/info.rb b/opensearch-api/lib/opensearch/api/actions/remote/info.rb index 9b35c750e..e46a390e2 100644 --- a/opensearch-api/lib/opensearch/api/actions/remote/info.rb +++ b/opensearch-api/lib/opensearch/api/actions/remote/info.rb @@ -31,9 +31,9 @@ module Actions # Returns all of the configured remote cluster information # # - def info(arguments = {}) + def info(_arguments = {}) method = HTTP_GET - path = "_remote/info" + path = '_remote/info' params = {} body = nil diff --git a/opensearch-api/lib/opensearch/api/actions/render_search_template.rb b/opensearch-api/lib/opensearch/api/actions/render_search_template.rb index d538faabf..1dd57ce1c 100644 --- a/opensearch-api/lib/opensearch/api/actions/render_search_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/render_search_template.rb @@ -50,7 +50,7 @@ def render_search_template(arguments = {}) path = if _id "_render/template/#{Utils.__listify(_id)}" else - "_render/template" + '_render/template' end params = {} diff --git a/opensearch-api/lib/opensearch/api/actions/scripts_painless_execute.rb b/opensearch-api/lib/opensearch/api/actions/scripts_painless_execute.rb index d7dce0fa8..86c5c4cef 100644 --- a/opensearch-api/lib/opensearch/api/actions/scripts_painless_execute.rb +++ b/opensearch-api/lib/opensearch/api/actions/scripts_painless_execute.rb @@ -48,7 +48,7 @@ def scripts_painless_execute(arguments = {}) OpenSearch::API::HTTP_GET end - path = "_scripts/painless/_execute" + path = '_scripts/painless/_execute' params = {} body = arguments[:body] diff --git a/opensearch-api/lib/opensearch/api/actions/scroll.rb b/opensearch-api/lib/opensearch/api/actions/scroll.rb index 8308b4270..3ec06a84e 100644 --- a/opensearch-api/lib/opensearch/api/actions/scroll.rb +++ b/opensearch-api/lib/opensearch/api/actions/scroll.rb @@ -57,7 +57,7 @@ def scroll(arguments = {}) path = if _scroll_id "_search/scroll/#{Utils.__listify(_scroll_id)}" else - "_search/scroll" + '_search/scroll' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -68,10 +68,10 @@ def scroll(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:scroll, [ - :scroll, - :scroll_id, - :rest_total_hits_as_int + ParamsRegistry.register(:scroll, %i[ + scroll + scroll_id + rest_total_hits_as_int ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/search.rb b/opensearch-api/lib/opensearch/api/actions/search.rb index 0cd825f8b..dec2f1c55 100644 --- a/opensearch-api/lib/opensearch/api/actions/search.rb +++ b/opensearch-api/lib/opensearch/api/actions/search.rb @@ -98,7 +98,7 @@ def search(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_search" else - "_search" + '_search' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -109,50 +109,50 @@ def search(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:search, [ - :analyzer, - :analyze_wildcard, - :ccs_minimize_roundtrips, - :default_operator, - :df, - :explain, - :stored_fields, - :docvalue_fields, - :from, - :ignore_unavailable, - :ignore_throttled, - :allow_no_indices, - :expand_wildcards, - :lenient, - :preference, - :q, - :routing, - :scroll, - :search_type, - :size, - :sort, - :_source, - :_source_excludes, - :_source_includes, - :terminate_after, - :stats, - :suggest_field, - :suggest_mode, - :suggest_size, - :suggest_text, - :timeout, - :track_scores, - :track_total_hits, - :allow_partial_search_results, - :typed_keys, - :version, - :seq_no_primary_term, - :request_cache, - :batched_reduce_size, - :max_concurrent_shard_requests, - :pre_filter_shard_size, - :rest_total_hits_as_int, - :min_compatible_shard_node + ParamsRegistry.register(:search, %i[ + analyzer + analyze_wildcard + ccs_minimize_roundtrips + default_operator + df + explain + stored_fields + docvalue_fields + from + ignore_unavailable + ignore_throttled + allow_no_indices + expand_wildcards + lenient + preference + q + routing + scroll + search_type + size + sort + _source + _source_excludes + _source_includes + terminate_after + stats + suggest_field + suggest_mode + suggest_size + suggest_text + timeout + track_scores + track_total_hits + allow_partial_search_results + typed_keys + version + seq_no_primary_term + request_cache + batched_reduce_size + max_concurrent_shard_requests + pre_filter_shard_size + rest_total_hits_as_int + min_compatible_shard_node ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/search_shards.rb b/opensearch-api/lib/opensearch/api/actions/search_shards.rb index 4318746a5..ac70f3ed6 100644 --- a/opensearch-api/lib/opensearch/api/actions/search_shards.rb +++ b/opensearch-api/lib/opensearch/api/actions/search_shards.rb @@ -50,7 +50,7 @@ def search_shards(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_search_shards" else - "_search_shards" + '_search_shards' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -61,13 +61,13 @@ def search_shards(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:search_shards, [ - :preference, - :routing, - :local, - :ignore_unavailable, - :allow_no_indices, - :expand_wildcards + ParamsRegistry.register(:search_shards, %i[ + preference + routing + local + ignore_unavailable + allow_no_indices + expand_wildcards ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/search_template.rb b/opensearch-api/lib/opensearch/api/actions/search_template.rb index 9dbcc1cb4..ba4ed4b48 100644 --- a/opensearch-api/lib/opensearch/api/actions/search_template.rb +++ b/opensearch-api/lib/opensearch/api/actions/search_template.rb @@ -65,7 +65,7 @@ def search_template(arguments = {}) path = if _index "#{Utils.__listify(_index)}/_search/template" else - "_search/template" + '_search/template' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -76,20 +76,20 @@ def search_template(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:search_template, [ - :ignore_unavailable, - :ignore_throttled, - :allow_no_indices, - :expand_wildcards, - :preference, - :routing, - :scroll, - :search_type, - :explain, - :profile, - :typed_keys, - :rest_total_hits_as_int, - :ccs_minimize_roundtrips + ParamsRegistry.register(:search_template, %i[ + ignore_unavailable + ignore_throttled + allow_no_indices + expand_wildcards + preference + routing + scroll + search_type + explain + profile + typed_keys + rest_total_hits_as_int + ccs_minimize_roundtrips ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/shutdown/get_node.rb b/opensearch-api/lib/opensearch/api/actions/shutdown/get_node.rb index 4f926f6cd..44a5056d0 100644 --- a/opensearch-api/lib/opensearch/api/actions/shutdown/get_node.rb +++ b/opensearch-api/lib/opensearch/api/actions/shutdown/get_node.rb @@ -49,7 +49,7 @@ def get_node(arguments = {}) path = if _node_id "_nodes/#{Utils.__listify(_node_id)}/shutdown" else - "_nodes/shutdown" + '_nodes/shutdown' end params = {} diff --git a/opensearch-api/lib/opensearch/api/actions/snapshot/cleanup_repository.rb b/opensearch-api/lib/opensearch/api/actions/snapshot/cleanup_repository.rb index f9c5f7b29..3162242df 100644 --- a/opensearch-api/lib/opensearch/api/actions/snapshot/cleanup_repository.rb +++ b/opensearch-api/lib/opensearch/api/actions/snapshot/cleanup_repository.rb @@ -57,10 +57,10 @@ def cleanup_repository(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:cleanup_repository, [ - :master_timeout, - :cluster_manager_timeout, - :timeout + ParamsRegistry.register(:cleanup_repository, %i[ + master_timeout + cluster_manager_timeout + timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/snapshot/clone.rb b/opensearch-api/lib/opensearch/api/actions/snapshot/clone.rb index 9b365689f..4a606991d 100644 --- a/opensearch-api/lib/opensearch/api/actions/snapshot/clone.rb +++ b/opensearch-api/lib/opensearch/api/actions/snapshot/clone.rb @@ -66,9 +66,9 @@ def clone(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:clone, [ - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:clone, %i[ + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/snapshot/create.rb b/opensearch-api/lib/opensearch/api/actions/snapshot/create.rb index e80cc12f5..0bf2b6c3c 100644 --- a/opensearch-api/lib/opensearch/api/actions/snapshot/create.rb +++ b/opensearch-api/lib/opensearch/api/actions/snapshot/create.rb @@ -62,10 +62,10 @@ def create(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:create, [ - :master_timeout, - :cluster_manager_timeout, - :wait_for_completion + ParamsRegistry.register(:create, %i[ + master_timeout + cluster_manager_timeout + wait_for_completion ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/snapshot/create_repository.rb b/opensearch-api/lib/opensearch/api/actions/snapshot/create_repository.rb index d5b0db02a..1b2501119 100644 --- a/opensearch-api/lib/opensearch/api/actions/snapshot/create_repository.rb +++ b/opensearch-api/lib/opensearch/api/actions/snapshot/create_repository.rb @@ -60,11 +60,11 @@ def create_repository(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:create_repository, [ - :master_timeout, - :cluster_manager_timeout, - :timeout, - :verify + ParamsRegistry.register(:create_repository, %i[ + master_timeout + cluster_manager_timeout + timeout + verify ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/snapshot/delete.rb b/opensearch-api/lib/opensearch/api/actions/snapshot/delete.rb index cbeaf9418..06b5e4601 100644 --- a/opensearch-api/lib/opensearch/api/actions/snapshot/delete.rb +++ b/opensearch-api/lib/opensearch/api/actions/snapshot/delete.rb @@ -64,9 +64,9 @@ def delete(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:delete, [ - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:delete, %i[ + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/snapshot/delete_repository.rb b/opensearch-api/lib/opensearch/api/actions/snapshot/delete_repository.rb index 1ca89e543..5f41bae86 100644 --- a/opensearch-api/lib/opensearch/api/actions/snapshot/delete_repository.rb +++ b/opensearch-api/lib/opensearch/api/actions/snapshot/delete_repository.rb @@ -61,10 +61,10 @@ def delete_repository(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:delete_repository, [ - :master_timeout, - :cluster_manager_timeout, - :timeout + ParamsRegistry.register(:delete_repository, %i[ + master_timeout + cluster_manager_timeout + timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/snapshot/get.rb b/opensearch-api/lib/opensearch/api/actions/snapshot/get.rb index a79123da6..9f445e54a 100644 --- a/opensearch-api/lib/opensearch/api/actions/snapshot/get.rb +++ b/opensearch-api/lib/opensearch/api/actions/snapshot/get.rb @@ -68,13 +68,13 @@ def get(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get, [ - :master_timeout, - :cluster_manager_timeout, - :ignore_unavailable, - :index_details, - :include_repository, - :verbose + ParamsRegistry.register(:get, %i[ + master_timeout + cluster_manager_timeout + ignore_unavailable + index_details + include_repository + verbose ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/snapshot/get_features.rb b/opensearch-api/lib/opensearch/api/actions/snapshot/get_features.rb index 9685f8ad8..e22c9ea8d 100644 --- a/opensearch-api/lib/opensearch/api/actions/snapshot/get_features.rb +++ b/opensearch-api/lib/opensearch/api/actions/snapshot/get_features.rb @@ -41,7 +41,7 @@ def get_features(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_snapshottable_features" + path = '_snapshottable_features' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil @@ -51,9 +51,9 @@ def get_features(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get_features, [ - :master_timeout, - :cluster_manager_timeout + ParamsRegistry.register(:get_features, %i[ + master_timeout + cluster_manager_timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/snapshot/get_repository.rb b/opensearch-api/lib/opensearch/api/actions/snapshot/get_repository.rb index c3d76bdca..969d3c081 100644 --- a/opensearch-api/lib/opensearch/api/actions/snapshot/get_repository.rb +++ b/opensearch-api/lib/opensearch/api/actions/snapshot/get_repository.rb @@ -47,7 +47,7 @@ def get_repository(arguments = {}) path = if _repository "_snapshot/#{Utils.__listify(_repository)}" else - "_snapshot" + '_snapshot' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -62,10 +62,10 @@ def get_repository(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get_repository, [ - :master_timeout, - :cluster_manager_timeout, - :local + ParamsRegistry.register(:get_repository, %i[ + master_timeout + cluster_manager_timeout + local ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/snapshot/repository_analyze.rb b/opensearch-api/lib/opensearch/api/actions/snapshot/repository_analyze.rb index d2fad8fa1..65c0b39ec 100644 --- a/opensearch-api/lib/opensearch/api/actions/snapshot/repository_analyze.rb +++ b/opensearch-api/lib/opensearch/api/actions/snapshot/repository_analyze.rb @@ -65,18 +65,18 @@ def repository_analyze(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:repository_analyze, [ - :blob_count, - :concurrency, - :read_node_count, - :early_read_node_count, - :seed, - :rare_action_probability, - :max_blob_size, - :max_total_data_size, - :timeout, - :detailed, - :rarely_abort_writes + ParamsRegistry.register(:repository_analyze, %i[ + blob_count + concurrency + read_node_count + early_read_node_count + seed + rare_action_probability + max_blob_size + max_total_data_size + timeout + detailed + rarely_abort_writes ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/snapshot/restore.rb b/opensearch-api/lib/opensearch/api/actions/snapshot/restore.rb index 0110b1304..fc010a657 100644 --- a/opensearch-api/lib/opensearch/api/actions/snapshot/restore.rb +++ b/opensearch-api/lib/opensearch/api/actions/snapshot/restore.rb @@ -62,10 +62,10 @@ def restore(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:restore, [ - :master_timeout, - :cluster_manager_timeout, - :wait_for_completion + ParamsRegistry.register(:restore, %i[ + master_timeout + cluster_manager_timeout + wait_for_completion ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/snapshot/status.rb b/opensearch-api/lib/opensearch/api/actions/snapshot/status.rb index 55ac7ccad..23236e1fe 100644 --- a/opensearch-api/lib/opensearch/api/actions/snapshot/status.rb +++ b/opensearch-api/lib/opensearch/api/actions/snapshot/status.rb @@ -53,7 +53,7 @@ def status(arguments = {}) elsif _repository "_snapshot/#{Utils.__listify(_repository)}/_status" else - "_snapshot/_status" + '_snapshot/_status' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -68,10 +68,10 @@ def status(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:status, [ - :master_timeout, - :cluster_manager_timeout, - :ignore_unavailable + ParamsRegistry.register(:status, %i[ + master_timeout + cluster_manager_timeout + ignore_unavailable ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/snapshot/verify_repository.rb b/opensearch-api/lib/opensearch/api/actions/snapshot/verify_repository.rb index bb1f352c5..5779507ef 100644 --- a/opensearch-api/lib/opensearch/api/actions/snapshot/verify_repository.rb +++ b/opensearch-api/lib/opensearch/api/actions/snapshot/verify_repository.rb @@ -57,10 +57,10 @@ def verify_repository(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:verify_repository, [ - :master_timeout, - :cluster_manager_timeout, - :timeout + ParamsRegistry.register(:verify_repository, %i[ + master_timeout + cluster_manager_timeout + timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/tasks/cancel.rb b/opensearch-api/lib/opensearch/api/actions/tasks/cancel.rb index 3e42f75b3..512282dd8 100644 --- a/opensearch-api/lib/opensearch/api/actions/tasks/cancel.rb +++ b/opensearch-api/lib/opensearch/api/actions/tasks/cancel.rb @@ -53,7 +53,7 @@ def cancel(arguments = {}) path = if _task_id "_tasks/#{Utils.__listify(_task_id)}/_cancel" else - "_tasks/_cancel" + '_tasks/_cancel' end params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) @@ -64,11 +64,11 @@ def cancel(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:cancel, [ - :nodes, - :actions, - :parent_task_id, - :wait_for_completion + ParamsRegistry.register(:cancel, %i[ + nodes + actions + parent_task_id + wait_for_completion ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/tasks/get.rb b/opensearch-api/lib/opensearch/api/actions/tasks/get.rb index 661f91e0f..9f021aad3 100644 --- a/opensearch-api/lib/opensearch/api/actions/tasks/get.rb +++ b/opensearch-api/lib/opensearch/api/actions/tasks/get.rb @@ -58,9 +58,9 @@ def get(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:get, [ - :wait_for_completion, - :timeout + ParamsRegistry.register(:get, %i[ + wait_for_completion + timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/tasks/list.rb b/opensearch-api/lib/opensearch/api/actions/tasks/list.rb index 710869bd2..67807438b 100644 --- a/opensearch-api/lib/opensearch/api/actions/tasks/list.rb +++ b/opensearch-api/lib/opensearch/api/actions/tasks/list.rb @@ -50,7 +50,7 @@ def list(arguments = {}) arguments = arguments.clone method = OpenSearch::API::HTTP_GET - path = "_tasks" + path = '_tasks' params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__) body = nil @@ -60,14 +60,14 @@ def list(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:list, [ - :nodes, - :actions, - :detailed, - :parent_task_id, - :wait_for_completion, - :group_by, - :timeout + ParamsRegistry.register(:list, %i[ + nodes + actions + detailed + parent_task_id + wait_for_completion + group_by + timeout ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/termvectors.rb b/opensearch-api/lib/opensearch/api/actions/termvectors.rb index ecedf9aa3..74f155e9a 100644 --- a/opensearch-api/lib/opensearch/api/actions/termvectors.rb +++ b/opensearch-api/lib/opensearch/api/actions/termvectors.rb @@ -84,24 +84,24 @@ def termvectors(arguments = {}) # Deprecated: Use the plural version, {#termvectors} # def termvector(arguments = {}) - termvectors(arguments.merge endpoint: '_termvector') + termvectors(arguments.merge(endpoint: '_termvector')) end # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:termvectors, [ - :term_statistics, - :field_statistics, - :fields, - :offsets, - :positions, - :payloads, - :preference, - :routing, - :realtime, - :version, - :version_type + ParamsRegistry.register(:termvectors, %i[ + term_statistics + field_statistics + fields + offsets + positions + payloads + preference + routing + realtime + version + version_type ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/update.rb b/opensearch-api/lib/opensearch/api/actions/update.rb index e4fc81c6e..41e8cca48 100644 --- a/opensearch-api/lib/opensearch/api/actions/update.rb +++ b/opensearch-api/lib/opensearch/api/actions/update.rb @@ -80,19 +80,19 @@ def update(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:update, [ - :wait_for_active_shards, - :_source, - :_source_excludes, - :_source_includes, - :lang, - :refresh, - :retry_on_conflict, - :routing, - :timeout, - :if_seq_no, - :if_primary_term, - :require_alias + ParamsRegistry.register(:update, %i[ + wait_for_active_shards + _source + _source_excludes + _source_includes + lang + refresh + retry_on_conflict + routing + timeout + if_seq_no + if_primary_term + require_alias ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/actions/update_by_query.rb b/opensearch-api/lib/opensearch/api/actions/update_by_query.rb index 8a3e07a03..4511ec634 100644 --- a/opensearch-api/lib/opensearch/api/actions/update_by_query.rb +++ b/opensearch-api/lib/opensearch/api/actions/update_by_query.rb @@ -95,42 +95,42 @@ def update_by_query(arguments = {}) # Register this action with its valid params when the module is loaded. # # @since 6.2.0 - ParamsRegistry.register(:update_by_query, [ - :analyzer, - :analyze_wildcard, - :default_operator, - :df, - :from, - :ignore_unavailable, - :allow_no_indices, - :conflicts, - :expand_wildcards, - :lenient, - :pipeline, - :preference, - :q, - :routing, - :scroll, - :search_type, - :search_timeout, - :size, - :max_docs, - :sort, - :_source, - :_source_excludes, - :_source_includes, - :terminate_after, - :stats, - :version, - :version_type, - :request_cache, - :refresh, - :timeout, - :wait_for_active_shards, - :scroll_size, - :wait_for_completion, - :requests_per_second, - :slices + ParamsRegistry.register(:update_by_query, %i[ + analyzer + analyze_wildcard + default_operator + df + from + ignore_unavailable + allow_no_indices + conflicts + expand_wildcards + lenient + pipeline + preference + q + routing + scroll + search_type + search_timeout + size + max_docs + sort + _source + _source_excludes + _source_includes + terminate_after + stats + version + version_type + request_cache + refresh + timeout + wait_for_active_shards + scroll_size + wait_for_completion + requests_per_second + slices ].freeze) end end diff --git a/opensearch-api/lib/opensearch/api/namespace/cat.rb b/opensearch-api/lib/opensearch/api/namespace/cat.rb index 18aedfbe9..2e1560dc6 100644 --- a/opensearch-api/lib/opensearch/api/namespace/cat.rb +++ b/opensearch-api/lib/opensearch/api/namespace/cat.rb @@ -32,7 +32,9 @@ module Actions; end # Client for the "cat" namespace (includes the {Cat::Actions} methods) # class CatClient - include Common::Client, Common::Client::Base, Cat::Actions + include Cat::Actions + include Common::Client::Base + include Common::Client end # Proxy method for {CatClient}, available in the receiving object diff --git a/opensearch-api/lib/opensearch/api/namespace/cluster.rb b/opensearch-api/lib/opensearch/api/namespace/cluster.rb index 973a8747f..c10c7082e 100644 --- a/opensearch-api/lib/opensearch/api/namespace/cluster.rb +++ b/opensearch-api/lib/opensearch/api/namespace/cluster.rb @@ -32,7 +32,9 @@ module Actions; end # Client for the "cluster" namespace (includes the {Cluster::Actions} methods) # class ClusterClient - include Common::Client, Common::Client::Base, Cluster::Actions + include Cluster::Actions + include Common::Client::Base + include Common::Client end # Proxy method for {ClusterClient}, available in the receiving object @@ -40,7 +42,6 @@ class ClusterClient def cluster @cluster ||= ClusterClient.new(self) end - end end end diff --git a/opensearch-api/lib/opensearch/api/namespace/common.rb b/opensearch-api/lib/opensearch/api/namespace/common.rb index ec49a191b..510b420e2 100644 --- a/opensearch-api/lib/opensearch/api/namespace/common.rb +++ b/opensearch-api/lib/opensearch/api/namespace/common.rb @@ -30,7 +30,6 @@ module Common module Actions; end module Client - # Base client wrapper # module Base @@ -43,11 +42,10 @@ def initialize(client) # Delegates the `perform_request` method to the wrapped client # - def perform_request(method, path, params={}, body=nil, headers=nil) + def perform_request(method, path, params = {}, body = nil, headers = nil) client.perform_request method, path, params, body, headers end end - end end end diff --git a/opensearch-api/lib/opensearch/api/namespace/dangling_indices.rb b/opensearch-api/lib/opensearch/api/namespace/dangling_indices.rb index 5da4c4696..ad4f8e2a4 100644 --- a/opensearch-api/lib/opensearch/api/namespace/dangling_indices.rb +++ b/opensearch-api/lib/opensearch/api/namespace/dangling_indices.rb @@ -28,10 +28,13 @@ module OpenSearch module API module DanglingIndices module Actions; end + # Client for the "dangling_indices" namespace (includes the {DanglingIndices::Actions} methods) # class DanglingIndicesClient - include Common::Client, Common::Client::Base, DanglingIndices::Actions + include DanglingIndices::Actions + include Common::Client::Base + include Common::Client end # Proxy method for {DanglingIndicesClient}, available in the receiving object diff --git a/opensearch-api/lib/opensearch/api/namespace/features.rb b/opensearch-api/lib/opensearch/api/namespace/features.rb index ed23dfba9..d01272838 100644 --- a/opensearch-api/lib/opensearch/api/namespace/features.rb +++ b/opensearch-api/lib/opensearch/api/namespace/features.rb @@ -32,7 +32,9 @@ module Actions; end # Client for the "features" namespace (includes the {Features::Actions} methods) # class FeaturesClient - include Common::Client, Common::Client::Base, Features::Actions + include Features::Actions + include Common::Client::Base + include Common::Client end # Proxy method for {FeaturesClient}, available in the receiving object diff --git a/opensearch-api/lib/opensearch/api/namespace/indices.rb b/opensearch-api/lib/opensearch/api/namespace/indices.rb index 321c43581..9e4b6f05d 100644 --- a/opensearch-api/lib/opensearch/api/namespace/indices.rb +++ b/opensearch-api/lib/opensearch/api/namespace/indices.rb @@ -32,7 +32,9 @@ module Actions; end # Client for the "indices" namespace (includes the {Indices::Actions} methods) # class IndicesClient - include Common::Client, Common::Client::Base, Indices::Actions + include Indices::Actions + include Common::Client::Base + include Common::Client end # Proxy method for {IndicesClient}, available in the receiving object @@ -40,7 +42,6 @@ class IndicesClient def indices @indices ||= IndicesClient.new(self) end - end end end diff --git a/opensearch-api/lib/opensearch/api/namespace/ingest.rb b/opensearch-api/lib/opensearch/api/namespace/ingest.rb index ffedbc064..be3683c26 100644 --- a/opensearch-api/lib/opensearch/api/namespace/ingest.rb +++ b/opensearch-api/lib/opensearch/api/namespace/ingest.rb @@ -32,7 +32,9 @@ module Actions; end # Client for the "ingest" namespace (includes the {Ingest::Actions} methods) # class IngestClient - include Common::Client, Common::Client::Base, Ingest::Actions + include Ingest::Actions + include Common::Client::Base + include Common::Client end # Proxy method for {IngestClient}, available in the receiving object @@ -40,7 +42,6 @@ class IngestClient def ingest @ingest ||= IngestClient.new(self) end - end end end diff --git a/opensearch-api/lib/opensearch/api/namespace/nodes.rb b/opensearch-api/lib/opensearch/api/namespace/nodes.rb index 766b4adf9..253e2efe2 100644 --- a/opensearch-api/lib/opensearch/api/namespace/nodes.rb +++ b/opensearch-api/lib/opensearch/api/namespace/nodes.rb @@ -32,7 +32,9 @@ module Actions; end # Client for the "nodes" namespace (includes the {Nodes::Actions} methods) # class NodesClient - include Common::Client, Common::Client::Base, Nodes::Actions + include Nodes::Actions + include Common::Client::Base + include Common::Client end # Proxy method for {NodesClient}, available in the receiving object @@ -40,7 +42,6 @@ class NodesClient def nodes @nodes ||= NodesClient.new(self) end - end end end diff --git a/opensearch-api/lib/opensearch/api/namespace/remote.rb b/opensearch-api/lib/opensearch/api/namespace/remote.rb index 34e24acef..53f85bc29 100644 --- a/opensearch-api/lib/opensearch/api/namespace/remote.rb +++ b/opensearch-api/lib/opensearch/api/namespace/remote.rb @@ -32,7 +32,9 @@ module Actions; end # Client for the "remote" namespace (includes the {Remote::Actions} methods) # class RemoteClient - include Common::Client, Common::Client::Base, Remote::Actions + include Remote::Actions + include Common::Client::Base + include Common::Client end # Proxy method for {RemoteClient}, available in the receiving object @@ -40,7 +42,6 @@ class RemoteClient def remote @remote ||= RemoteClient.new(self) end - end end end diff --git a/opensearch-api/lib/opensearch/api/namespace/security.rb b/opensearch-api/lib/opensearch/api/namespace/security.rb index ca537352e..7a7839d65 100644 --- a/opensearch-api/lib/opensearch/api/namespace/security.rb +++ b/opensearch-api/lib/opensearch/api/namespace/security.rb @@ -32,7 +32,9 @@ module Actions; end # Client for the "security" namespace (includes the {Security::Actions} methods) # class SecurityClient - include Common::Client, Common::Client::Base, Security::Actions + include Security::Actions + include Common::Client::Base + include Common::Client end # Proxy method for {SecurityClient}, available in the receiving object diff --git a/opensearch-api/lib/opensearch/api/namespace/shutdown.rb b/opensearch-api/lib/opensearch/api/namespace/shutdown.rb index ce9a4a113..414e604b8 100644 --- a/opensearch-api/lib/opensearch/api/namespace/shutdown.rb +++ b/opensearch-api/lib/opensearch/api/namespace/shutdown.rb @@ -32,7 +32,9 @@ module Actions; end # Client for the "shutdown" namespace (includes the {Shutdown::Actions} methods) # class ShutdownClient - include Common::Client, Common::Client::Base, Shutdown::Actions + include Shutdown::Actions + include Common::Client::Base + include Common::Client end # Proxy method for {ShutdownClient}, available in the receiving object @@ -40,7 +42,6 @@ class ShutdownClient def shutdown @shutdown ||= ShutdownClient.new(self) end - end end end diff --git a/opensearch-api/lib/opensearch/api/namespace/snapshot.rb b/opensearch-api/lib/opensearch/api/namespace/snapshot.rb index 0fd61f6b0..658706646 100644 --- a/opensearch-api/lib/opensearch/api/namespace/snapshot.rb +++ b/opensearch-api/lib/opensearch/api/namespace/snapshot.rb @@ -32,7 +32,9 @@ module Actions; end # Client for the "snapshot" namespace (includes the {Snapshot::Actions} methods) # class SnapshotClient - include Common::Client, Common::Client::Base, Snapshot::Actions + include Snapshot::Actions + include Common::Client::Base + include Common::Client end # Proxy method for {SnapshotClient}, available in the receiving object @@ -40,7 +42,6 @@ class SnapshotClient def snapshot @snapshot ||= SnapshotClient.new(self) end - end end end diff --git a/opensearch-api/lib/opensearch/api/namespace/tasks.rb b/opensearch-api/lib/opensearch/api/namespace/tasks.rb index 1a7a6095a..61535c6da 100644 --- a/opensearch-api/lib/opensearch/api/namespace/tasks.rb +++ b/opensearch-api/lib/opensearch/api/namespace/tasks.rb @@ -32,7 +32,9 @@ module Actions; end # Client for the "tasks" namespace (includes the {Tasks::Actions} methods) # class TasksClient - include Common::Client, Common::Client::Base, Tasks::Actions + include Tasks::Actions + include Common::Client::Base + include Common::Client end # Proxy method for {TasksClient}, available in the receiving object @@ -40,7 +42,6 @@ class TasksClient def tasks @tasks ||= TasksClient.new(self) end - end end end diff --git a/opensearch-api/lib/opensearch/api/utils.rb b/opensearch-api/lib/opensearch/api/utils.rb index 0e410ee61..76af95404 100644 --- a/opensearch-api/lib/opensearch/api/utils.rb +++ b/opensearch-api/lib/opensearch/api/utils.rb @@ -26,11 +26,9 @@ module OpenSearch module API - # Generic utility methods # module Utils - # URL-escape a string # # @example @@ -40,6 +38,7 @@ module Utils # @api private def __escape(string) return string if string == '*' + CGI.escape(string.to_s) end @@ -62,12 +61,12 @@ def __listify(*list) options = list.last.is_a?(Hash) ? list.pop : {} escape = options[:escape] - Array(list). - flat_map { |e| e.respond_to?(:split) ? e.split(',') : e }. - flatten. - compact. - map { |e| escape == false ? e : __escape(e) }. - join(',') + Array(list) + .flat_map { |e| e.respond_to?(:split) ? e.split(',') : e } + .flatten + .compact + .map { |e| escape == false ? e : __escape(e) } + .join(',') end # Create a path (URL part) from arguments, ignoring nil values and empty strings. @@ -83,11 +82,11 @@ def __listify(*list) # # @api private def __pathify(*segments) - Array(segments).flatten. - compact. - reject { |s| s.to_s.strip.empty? }. - join('/'). - squeeze('/') + Array(segments).flatten + .compact + .reject { |s| s.to_s.strip.empty? } + .join('/') + .squeeze('/') end # Convert an array of payloads into OpenSearch `header\ndata` format @@ -109,25 +108,24 @@ def __pathify(*segments) def __bulkify(payload) operations = %w[index create delete update] - case - # Hashes with `:data` - when payload.any? { |d| d.is_a?(Hash) && d.values.first.is_a?(Hash) && operations.include?(d.keys.first.to_s) && (d.values.first[:data] || d.values.first['data']) } - payload = payload. - inject([]) do |sum, item| - operation, meta = item.to_a.first - meta = meta.clone - data = meta.delete(:data) || meta.delete('data') - - sum << { operation => meta } - sum << data if data - sum - end. - map { |item| OpenSearch::API.serializer.dump(item) } + if payload.any? do |d| + d.is_a?(Hash) && d.values.first.is_a?(Hash) && operations.include?(d.keys.first.to_s) && (d.values.first[:data] || d.values.first['data']) + end + payload = payload + .each_with_object([]) do |item, sum| + operation, meta = item.to_a.first + meta = meta.clone + data = meta.delete(:data) || meta.delete('data') + + sum << { operation => meta } + sum << data if data + end + .map { |item| OpenSearch::API.serializer.dump(item) } payload << '' unless payload.empty? # Array of strings - when payload.all? { |d| d.is_a? String } + elsif payload.all? { |d| d.is_a? String } payload << '' # Header/Data pairs @@ -166,27 +164,26 @@ def __bulkify(payload) # # @api private # - def __validate_and_extract_params(arguments, params=[], options={}) + def __validate_and_extract_params(arguments, params = [], options = {}) if options[:skip_parameter_validation] || OpenSearch::API.settings[:skip_parameter_validation] arguments else __validate_params(arguments, params) - __extract_params(arguments, params, options.merge(:escape => false)) + __extract_params(arguments, params, options.merge(escape: false)) end end - def __validate_params(arguments, valid_params=[]) - arguments.each do |k,v| + def __validate_params(arguments, valid_params = []) + arguments.each do |k, _v| raise ArgumentError, "URL parameter '#{k}' is not supported" \ unless COMMON_PARAMS.include?(k) || COMMON_QUERY_PARAMS.include?(k) || valid_params.include?(k) end end - def __extract_params(arguments, params=[], options={}) - result = arguments.select { |k,v| COMMON_QUERY_PARAMS.include?(k) || params.include?(k) } - result = Hash[result] unless result.is_a?(Hash) # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour - result = Hash[result.map { |k,v| v.is_a?(Array) ? [k, __listify(v, options)] : [k,v] }] # Listify Arrays - result + def __extract_params(arguments, params = [], options = {}) + result = arguments.select { |k, _v| COMMON_QUERY_PARAMS.include?(k) || params.include?(k) } + result = result.to_h unless result.is_a?(Hash) # Normalize Ruby 1.8 and Ruby 1.9 Hash#select behaviour + result.map { |k, v| v.is_a?(Array) ? [k, __listify(v, options)] : [k, v] }.to_h # Listify Arrays end # Extracts the valid parts of the URL from the arguments @@ -205,12 +202,15 @@ def __extract_params(arguments, params=[], options={}) # # @api private # - def __extract_parts(arguments, valid_parts=[]) - parts = Hash[arguments.select { |k,v| valid_parts.include?(k) }] - parts = parts.reduce([]) { |sum, item| k, v = item; v.is_a?(TrueClass) ? sum << k.to_s : sum << v } + def __extract_parts(arguments, valid_parts = []) + parts = arguments.select { |k, _v| valid_parts.include?(k) }.to_h + parts = parts.reduce([]) do |sum, item| + k, v = item + sum << (v.is_a?(TrueClass) ? k.to_s : v) + end - arguments.delete_if { |k,v| valid_parts.include? k } - return parts + arguments.delete_if { |k, _v| valid_parts.include? k } + parts end # Calls the given block, rescuing from `StandardError`. @@ -224,7 +224,7 @@ def __extract_parts(arguments, valid_parts=[]) # # @api private # - def __rescue_from_not_found(&block) + def __rescue_from_not_found yield rescue StandardError => e if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found/i @@ -234,25 +234,27 @@ def __rescue_from_not_found(&block) end end - def __report_unsupported_parameters(arguments, params=[]) + def __report_unsupported_parameters(arguments, params = []) messages = [] - unsupported_params = params.select {|d| d.is_a?(Hash) ? arguments.include?(d.keys.first) : arguments.include?(d) } + unsupported_params = params.select do |d| + d.is_a?(Hash) ? arguments.include?(d.keys.first) : arguments.include?(d) + end unsupported_params.each do |param| name = case param - when Symbol - param - when Hash - param.keys.first - else - raise ArgumentError, "The param must be a Symbol or a Hash" - end + when Symbol + param + when Hash + param.keys.first + else + raise ArgumentError, 'The param must be a Symbol or a Hash' + end explanation = if param.is_a?(Hash) - ". #{param.values.first[:explanation]}." - else - ". This parameter is not supported in the version you're using: #{OpenSearch::API::VERSION}, and will be removed in the next release." - end + ". #{param.values.first[:explanation]}." + else + ". This parameter is not supported in the version you're using: #{OpenSearch::API::VERSION}, and will be removed in the next release." + end message = "[!] You are using unsupported parameter [:#{name}]" @@ -266,7 +268,7 @@ def __report_unsupported_parameters(arguments, params=[]) end unless messages.empty? - messages << "Suppress this warning by the `-WO` command line flag." + messages << 'Suppress this warning by the `-WO` command line flag.' if STDERR.tty? Kernel.warn messages.map { |m| "\e[31;1m#{m}\e[0m" }.join("\n") diff --git a/opensearch-api/opensearch-api.gemspec b/opensearch-api/opensearch-api.gemspec index 38755a295..edf0f397d 100644 --- a/opensearch-api/opensearch-api.gemspec +++ b/opensearch-api/opensearch-api.gemspec @@ -25,16 +25,17 @@ # under the License. # coding: utf-8 -lib = File.expand_path('../lib', __FILE__) + +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'opensearch/api/version' -signing_key_path = File.expand_path("../gem-private_key.pem") +signing_key_path = File.expand_path('../gem-private_key.pem') Gem::Specification.new do |s| s.name = 'opensearch-api' s.version = OpenSearch::API::VERSION - s.authors = ['Jayesh Hathila', 'Vamshi Vijay Nakkirtha', 'Vijayan Balasubramanian' , 'Yuvraj Jaiswal'] + s.authors = ['Jayesh Hathila', 'Vamshi Vijay Nakkirtha', 'Vijayan Balasubramanian', 'Yuvraj Jaiswal'] s.email = ['jayehh@amazon.com', 'vamshin@amazon.com', 'balasvij@amazon.com', 'jaiyuvra@amazon.com'] s.summary = 'Ruby API for OpenSearch.' s.homepage = 'https://opensearch.org/docs/latest/' @@ -42,21 +43,22 @@ Gem::Specification.new do |s| s.metadata = { 'homepage_uri' => 'https://opensearch.org/docs/latest/', 'source_code_uri' => 'https://github.com/opensearch-project/opensearch-ruby/tree/main/opensearch-api', - 'bug_tracker_uri' => 'https://github.com/opensearch-project/opensearch-ruby/issues' + 'bug_tracker_uri' => 'https://github.com/opensearch-project/opensearch-ruby/issues', + 'rubygems_mfa_required' => 'true' } s.files = `git ls-files`.split($/) s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) } s.test_files = s.files.grep(%r{^(test|spec|features)/}) - if $PROGRAM_NAME.end_with?("gem") && ARGV == ["build", __FILE__] && File.exist?(signing_key_path) + if $PROGRAM_NAME.end_with?('gem') && ARGV == ['build', __FILE__] && File.exist?(signing_key_path) s.signing_key = signing_key_path s.cert_chain = ['../certs/opensearch-rubygems.pem'] end s.require_paths = ['lib'] - s.extra_rdoc_files = [ 'README.md', 'LICENSE' ] - s.rdoc_options = [ '--charset=UTF-8' ] + s.extra_rdoc_files = ['README.md', 'LICENSE'] + s.rdoc_options = ['--charset=UTF-8'] s.required_ruby_version = '>= 2.4' @@ -64,26 +66,26 @@ Gem::Specification.new do |s| s.add_development_dependency 'ansi' s.add_development_dependency 'bundler' - s.add_development_dependency 'opensearch-ruby', '~> 2' - s.add_development_dependency 'opensearch-transport' s.add_development_dependency 'minitest' s.add_development_dependency 'minitest-reporters' s.add_development_dependency 'mocha' + s.add_development_dependency 'opensearch-ruby', '~> 2' + s.add_development_dependency 'opensearch-transport' s.add_development_dependency 'pry' s.add_development_dependency 'rake', '~> 13' s.add_development_dependency 'shoulda-context' s.add_development_dependency 'yard' # Gems for testing integrations - s.add_development_dependency 'jsonify' s.add_development_dependency 'hashie' + s.add_development_dependency 'jsonify' s.add_development_dependency 'cane' s.add_development_dependency 'jbuilder' s.add_development_dependency 'require-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius) + s.add_development_dependency 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius) s.add_development_dependency 'simplecov' s.add_development_dependency 'test-unit', '~> 2' - s.add_development_dependency 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius) s.description = <<-DESC.gsub(/^ /, '') Ruby API for OpenSearch. See the `opensearch-ruby` gem for full integration. diff --git a/opensearch-api/spec/opensearch/api/actions/abort_benchmark_spec.rb b/opensearch-api/spec/opensearch/api/actions/abort_benchmark_spec.rb index 7aa32cf2e..9fecd1967 100644 --- a/opensearch-api/spec/opensearch/api/actions/abort_benchmark_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/abort_benchmark_spec.rb @@ -27,7 +27,6 @@ require 'spec_helper' describe 'client#abort_benchmark' do - let(:expected_args) do [ 'POST', diff --git a/opensearch-api/spec/opensearch/api/actions/benchmark_spec.rb b/opensearch-api/spec/opensearch/api/actions/benchmark_spec.rb index f027576ad..9f61449f6 100644 --- a/opensearch-api/spec/opensearch/api/actions/benchmark_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/benchmark_spec.rb @@ -27,7 +27,6 @@ require 'spec_helper' describe 'client#benchmark' do - let(:expected_args) do [ 'PUT', diff --git a/opensearch-api/spec/opensearch/api/actions/bulk_spec.rb b/opensearch-api/spec/opensearch/api/actions/bulk_spec.rb index f61fdf2f1..e33898440 100644 --- a/opensearch-api/spec/opensearch/api/actions/bulk_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/bulk_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client#bulk' do - let(:expected_args) do [ - 'POST', - url, - params, - body, - headers + 'POST', + url, + params, + body, + headers ] end @@ -44,7 +43,6 @@ let(:body) { '' } context 'when a list of operations is provided' do - let(:body) do <<-PAYLOAD.gsub(/^\s+/, '') {"index":{"_index":"myindexA","_id":"1"}} @@ -58,17 +56,16 @@ end it 'performs the request' do - expect(client_double.bulk(:body => [ - { :index => { :_index => 'myindexA', :_id => '1', :data => { :title => 'Test' } } }, - { :update => { :_index => 'myindexB', :_id => '2', :data => { :doc => { :title => 'Update' } } } }, - { :delete => { :_index => 'myindexC', :_id => '3' } }, - { :index => { :_index => 'myindexD', :_id => '1', :data => { :data => 'MYDATA' } } }, - ])).to eq({}) + expect(client_double.bulk(body: [ + { index: { _index: 'myindexA', _id: '1', data: { title: 'Test' } } }, + { update: { _index: 'myindexB', _id: '2', data: { doc: { title: 'Update' } } } }, + { delete: { _index: 'myindexC', _id: '3' } }, + { index: { _index: 'myindexD', _id: '1', data: { data: 'MYDATA' } } } + ])).to eq({}) end end context 'when an index is specified' do - let(:url) { 'myindex/_bulk' } it 'performs the request' do @@ -77,7 +74,6 @@ end context 'when there are data keys in the head/data payloads' do - let(:body) do <<-PAYLOAD.gsub(/^\s+/, '') {"update":{"_index":"myindex","_id":"1"}} @@ -86,13 +82,12 @@ end it 'performs the request' do - expect(client_double.bulk(body:[ { :update => { :_index => 'myindex', :_id => '1' } }, - { :doc => { :data => { :title => 'Update' } } } ])).to eq({}) + expect(client_double.bulk(body: [{ update: { _index: 'myindex', _id: '1' } }, + { doc: { data: { title: 'Update' } } }])).to eq({}) end end context 'when the payload is a string' do - let(:body) do 'foo\nbar' end @@ -103,18 +98,16 @@ end context 'when the payload is an array of Strings' do - let(:body) do "foo\nbar\n" end it 'performs the request' do - expect(client_double.bulk(body: ['foo', 'bar'])).to eq({}) + expect(client_double.bulk(body: %w[foo bar])).to eq({}) end end context 'when there are parameters' do - let(:params) do { refresh: true } end @@ -125,7 +118,6 @@ end context 'when url characters need to be URL-escaped' do - let(:url) do 'foo%5Ebar/_bulk' end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/aliases_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/aliases_spec.rb index d4cab9eea..074f57fe9 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/aliases_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/aliases_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#aliases' do - let(:expected_args) do [ - 'GET', - '_cat/aliases', - {}, - nil, - {} + 'GET', + '_cat/aliases', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/all_pit_segments_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/all_pit_segments_spec.rb index 43befe0f2..b0e48edb7 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/all_pit_segments_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/all_pit_segments_spec.rb @@ -10,7 +10,6 @@ require 'spec_helper' describe 'client.cat#all_pit_segments' do - let(:expected_args) do [ 'GET', @@ -25,9 +24,9 @@ end it 'does not accept unregistered params' do - expect { + expect do client.cat.all_pit_segments(something: :else) - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request' do diff --git a/opensearch-api/spec/opensearch/api/actions/cat/allocation_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/allocation_spec.rb index 047af6c86..1b35438e2 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/allocation_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/allocation_spec.rb @@ -31,7 +31,7 @@ [ 'GET', '_cat/allocation', - {cluster_manager_timeout: 2}, + { cluster_manager_timeout: 2 }, nil, {} ] diff --git a/opensearch-api/spec/opensearch/api/actions/cat/count_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/count_spec.rb index fe54eeb76..b4a080487 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/count_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/count_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#count' do - let(:expected_args) do [ - 'GET', - '_cat/count', - {}, - nil, - {} + 'GET', + '_cat/count', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/fielddata_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/fielddata_spec.rb index 875a6aea0..17e1db977 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/fielddata_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/fielddata_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#fielddata' do - let(:expected_args) do [ - 'GET', - '_cat/fielddata', - {}, - nil, - {} + 'GET', + '_cat/fielddata', + {}, + nil, + {} ] end @@ -43,19 +42,18 @@ end context 'when field are specified' do - let(:expected_args) do [ - 'GET', - '_cat/fielddata/foo,bar', - {}, - nil, - {} + 'GET', + '_cat/fielddata/foo,bar', + {}, + nil, + {} ] end it 'performs the request' do - expect(client_double.cat.fielddata(fields: ['foo', 'bar'])).to eq({}) + expect(client_double.cat.fielddata(fields: %w[foo bar])).to eq({}) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/health_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/health_spec.rb index cf3d2e491..2be97fddd 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/health_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/health_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#health' do - let(:expected_args) do [ - 'GET', - '_cat/health', - {}, - nil, - {} + 'GET', + '_cat/health', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/help_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/help_spec.rb index 0792bb3e4..06a60c62b 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/help_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/help_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#help' do - let(:expected_args) do [ - 'GET', - '_cat', - {}, - nil, - {} + 'GET', + '_cat', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/indices_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/indices_spec.rb index 63bd0c385..dba817e03 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/indices_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/indices_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#indices' do - let(:expected_args) do [ - 'GET', - '_cat/indices', - {}, - nil, - {} + 'GET', + '_cat/indices', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/master_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/master_spec.rb index 84efbb12c..18c7462fb 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/master_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/master_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#master' do - let(:expected_args) do [ - 'GET', - '_cat/master', - {}, - nil, - {} + 'GET', + '_cat/master', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/nodeattrs_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/nodeattrs_spec.rb index fb3e0b1cb..af739667e 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/nodeattrs_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/nodeattrs_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#nodeattrs' do - let(:expected_args) do [ - 'GET', - '_cat/nodeattrs', - {}, - nil, - {} + 'GET', + '_cat/nodeattrs', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/nodes_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/nodes_spec.rb index 2e06ac636..09db6d7cc 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/nodes_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/nodes_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#nodes' do - let(:expected_args) do [ - 'GET', - '_cat/nodes', - {}, - nil, - {} + 'GET', + '_cat/nodes', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/pending_tasks_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/pending_tasks_spec.rb index aa61d15a4..3432b24be 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/pending_tasks_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/pending_tasks_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#pending_tasks' do - let(:expected_args) do [ - 'GET', - '_cat/pending_tasks', - {}, - nil, - {} + 'GET', + '_cat/pending_tasks', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/pit_segments_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/pit_segments_spec.rb index 3235737e0..05504cc65 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/pit_segments_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/pit_segments_spec.rb @@ -10,7 +10,6 @@ require 'spec_helper' describe 'client.cat#pit_segments' do - let(:expected_args) do [ 'GET', @@ -26,15 +25,15 @@ end it 'requires the :body argument' do - expect { + expect do client.cat.pit_segments - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'does not accept unregistered params' do - expect { + expect do client.cat.pit_segments(body: {}, something: :else) - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request' do diff --git a/opensearch-api/spec/opensearch/api/actions/cat/plugins_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/plugins_spec.rb index f8ed62ad6..a5e52f653 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/plugins_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/plugins_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#plugins' do - let(:expected_args) do [ - 'GET', - '_cat/plugins', - {}, - nil, - {} + 'GET', + '_cat/plugins', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/recovery_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/recovery_spec.rb index de3c6e2eb..d43c4f3f3 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/recovery_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/recovery_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#recovery' do - let(:expected_args) do [ - 'GET', - '_cat/recovery', - {}, - nil, - {} + 'GET', + '_cat/recovery', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/repositories_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/repositories_spec.rb index c4eadff4d..569a15c47 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/repositories_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/repositories_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#repositories' do - let(:expected_args) do [ - 'GET', - '_cat/repositories', - {}, - nil, - {} + 'GET', + '_cat/repositories', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/segments_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/segments_spec.rb index 18a9696ed..a9b9d9553 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/segments_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/segments_spec.rb @@ -27,7 +27,6 @@ require 'spec_helper' describe 'client.cat#segments' do - let(:expected_args) do [ 'GET', diff --git a/opensearch-api/spec/opensearch/api/actions/cat/shards_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/shards_spec.rb index 965cd3c14..eefd44895 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/shards_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/shards_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#shards' do - let(:expected_args) do [ - 'GET', - '_cat/shards', - {}, - nil, - {} + 'GET', + '_cat/shards', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/snapshot_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/snapshot_spec.rb index f12537e75..792b055ea 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/snapshot_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/snapshot_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#snapshots' do - let(:expected_args) do [ - 'GET', - '_cat/snapshots/foo', - {}, - nil, - {} + 'GET', + '_cat/snapshots/foo', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/tasks_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/tasks_spec.rb index a224c073c..a34743b30 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/tasks_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/tasks_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#tasks' do - let(:expected_args) do [ - 'GET', - '_cat/tasks', - {}, - nil, - {} + 'GET', + '_cat/tasks', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/templates_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/templates_spec.rb index 8e75a7a62..85c2a8981 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/templates_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/templates_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#templates' do - let(:expected_args) do [ - 'GET', - '_cat/templates', - {}, - nil, - {} + 'GET', + '_cat/templates', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cat/thread_pool_spec.rb b/opensearch-api/spec/opensearch/api/actions/cat/thread_pool_spec.rb index 30efba4e7..82795dcfc 100644 --- a/opensearch-api/spec/opensearch/api/actions/cat/thread_pool_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cat/thread_pool_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cat#thread_pool' do - let(:expected_args) do [ - 'GET', - '_cat/thread_pool', - {}, - nil, - {} + 'GET', + '_cat/thread_pool', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/clear_scroll_spec.rb b/opensearch-api/spec/opensearch/api/actions/clear_scroll_spec.rb index 3759dd3db..38d63be5b 100644 --- a/opensearch-api/spec/opensearch/api/actions/clear_scroll_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/clear_scroll_spec.rb @@ -27,7 +27,6 @@ require 'spec_helper' describe 'client#clear_scroll' do - let(:expected_args) do [ 'DELETE', @@ -43,19 +42,18 @@ end context 'when a list of scroll ids is provided' do - let(:expected_args) do [ - 'DELETE', - '_search/scroll/abc123,def456', - {}, - nil, - {} + 'DELETE', + '_search/scroll/abc123,def456', + {}, + nil, + {} ] end it 'performs the request' do - expect(client_double.clear_scroll(scroll_id: ['abc123', 'def456'])).to eq({}) + expect(client_double.clear_scroll(scroll_id: %w[abc123 def456])).to eq({}) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/cluster/allocation_explain_spec.rb b/opensearch-api/spec/opensearch/api/actions/cluster/allocation_explain_spec.rb index 702fe89c9..e746161a9 100644 --- a/opensearch-api/spec/opensearch/api/actions/cluster/allocation_explain_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cluster/allocation_explain_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#allocation_explain' do - let(:expected_args) do [ - 'GET', - '_cluster/allocation/explain', - {}, - nil, - {} + 'GET', + '_cluster/allocation/explain', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cluster/get_settings_spec.rb b/opensearch-api/spec/opensearch/api/actions/cluster/get_settings_spec.rb index e52f95adf..7fa50bd51 100644 --- a/opensearch-api/spec/opensearch/api/actions/cluster/get_settings_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cluster/get_settings_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#get_settings' do - let(:expected_args) do [ - 'GET', - '_cluster/settings', - {}, - nil, - {} + 'GET', + '_cluster/settings', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cluster/health_spec.rb b/opensearch-api/spec/opensearch/api/actions/cluster/health_spec.rb index 98c302e79..19574d5dd 100644 --- a/opensearch-api/spec/opensearch/api/actions/cluster/health_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cluster/health_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#health' do - let(:expected_args) do [ - 'GET', - '_cluster/health', - {}, - nil, - {} + 'GET', + '_cluster/health', + {}, + nil, + {} ] end @@ -43,14 +42,13 @@ end context 'when a level is specified' do - let(:expected_args) do [ - 'GET', - '_cluster/health', - { level: 'indices' }, - nil, - {} + 'GET', + '_cluster/health', + { level: 'indices' }, + nil, + {} ] end @@ -60,14 +58,13 @@ end context 'when an index is specified' do - let(:expected_args) do [ - 'GET', - '_cluster/health/foo', - {}, - nil, - {} + 'GET', + '_cluster/health/foo', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cluster/pending_tasks_spec.rb b/opensearch-api/spec/opensearch/api/actions/cluster/pending_tasks_spec.rb index 13ef9e8d4..a975260d8 100644 --- a/opensearch-api/spec/opensearch/api/actions/cluster/pending_tasks_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cluster/pending_tasks_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#pending_tasks' do - let(:expected_args) do [ - 'GET', - '_cluster/pending_tasks', - {}, - nil, - {} + 'GET', + '_cluster/pending_tasks', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cluster/put_settings_spec.rb b/opensearch-api/spec/opensearch/api/actions/cluster/put_settings_spec.rb index fcf1f94d3..bb2f0c823 100644 --- a/opensearch-api/spec/opensearch/api/actions/cluster/put_settings_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cluster/put_settings_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#put_settings' do - let(:expected_args) do [ - 'PUT', - '_cluster/settings', - {}, - {}, - {} + 'PUT', + '_cluster/settings', + {}, + {}, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cluster/remote_info_spec.rb b/opensearch-api/spec/opensearch/api/actions/cluster/remote_info_spec.rb index ff70fad54..23e809664 100644 --- a/opensearch-api/spec/opensearch/api/actions/cluster/remote_info_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cluster/remote_info_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#remote_info' do - let(:expected_args) do [ - 'GET', - '_remote/info', - {}, - nil, - {} + 'GET', + '_remote/info', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/cluster/reroute_spec.rb b/opensearch-api/spec/opensearch/api/actions/cluster/reroute_spec.rb index f88f20654..dd43e160d 100644 --- a/opensearch-api/spec/opensearch/api/actions/cluster/reroute_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cluster/reroute_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#reroute' do - let(:expected_args) do [ - 'POST', - '_cluster/reroute', - {}, - {}, - {} + 'POST', + '_cluster/reroute', + {}, + {}, + {} ] end @@ -43,19 +42,18 @@ end context 'when a body is specified' do - let(:expected_args) do [ - 'POST', - '_cluster/reroute', - {}, - { commands: [ move: { index: 'myindex', shard: 0 }] }, - {} + 'POST', + '_cluster/reroute', + {}, + { commands: [move: { index: 'myindex', shard: 0 }] }, + {} ] end it 'performs the request' do - expect(client_double.cluster.reroute(body: { commands: [ move: { index: 'myindex', shard: 0 }] })).to eq({}) + expect(client_double.cluster.reroute(body: { commands: [move: { index: 'myindex', shard: 0 }] })).to eq({}) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/cluster/state_spec.rb b/opensearch-api/spec/opensearch/api/actions/cluster/state_spec.rb index 3f7f6b996..c843b915c 100644 --- a/opensearch-api/spec/opensearch/api/actions/cluster/state_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cluster/state_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#state' do - let(:expected_args) do [ - 'GET', - '_cluster/state', - {}, - nil, - {} + 'GET', + '_cluster/state', + {}, + nil, + {} ] end @@ -43,19 +42,18 @@ end context 'when a metric is specified' do - let(:expected_args) do [ - 'GET', - '_cluster/state/foo,bar', - {}, - nil, - {} + 'GET', + '_cluster/state/foo,bar', + {}, + nil, + {} ] end it 'performs the request' do - expect(client_double.cluster.state(metric: ['foo', 'bar'])).to eq({}) + expect(client_double.cluster.state(metric: %w[foo bar])).to eq({}) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/cluster/stats_spec.rb b/opensearch-api/spec/opensearch/api/actions/cluster/stats_spec.rb index 2e86dcbcd..d1f671f5a 100644 --- a/opensearch-api/spec/opensearch/api/actions/cluster/stats_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/cluster/stats_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#stats' do - let(:expected_args) do [ - 'GET', - '_cluster/stats', - {}, - nil, - {} + 'GET', + '_cluster/stats', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/count_spec.rb b/opensearch-api/spec/opensearch/api/actions/count_spec.rb index 213244782..9e326009e 100644 --- a/opensearch-api/spec/opensearch/api/actions/count_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/count_spec.rb @@ -27,7 +27,6 @@ require 'spec_helper' describe 'client#count' do - let(:expected_args) do [ 'POST', @@ -43,7 +42,6 @@ end context 'when an index is specified' do - let(:expected_args) do [ 'POST', @@ -55,12 +53,11 @@ end it 'performs the request' do - expect(client_double.count(index: ['foo','bar'])).to eq({}) + expect(client_double.count(index: %w[foo bar])).to eq({}) end end context 'when there is a query provided' do - let(:expected_args) do [ 'POST', diff --git a/opensearch-api/spec/opensearch/api/actions/create_document_spec.rb b/opensearch-api/spec/opensearch/api/actions/create_document_spec.rb index 89543ad86..a9a8a4a30 100644 --- a/opensearch-api/spec/opensearch/api/actions/create_document_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/create_document_spec.rb @@ -27,30 +27,28 @@ require 'spec_helper' describe 'client#create_document' do - let(:expected_args) do [ - 'PUT', - 'foo/_doc/123', - { op_type: 'create' }, - { foo: 'bar' }, - {} + 'PUT', + 'foo/_doc/123', + { op_type: 'create' }, + { foo: 'bar' }, + {} ] end it 'performs the request' do - expect(client_double.create(index: 'foo', id: '123', body: { foo: 'bar'})).to eq({}) + expect(client_double.create(index: 'foo', id: '123', body: { foo: 'bar' })).to eq({}) end context 'when the request needs to be URL-escaped' do - let(:expected_args) do [ - 'PUT', - 'foo%5Ebar/_doc/123', - { op_type: 'create' }, - {}, - {} + 'PUT', + 'foo%5Ebar/_doc/123', + { op_type: 'create' }, + {}, + {} ] end @@ -60,14 +58,13 @@ end context 'when an id is provided as an integer' do - let(:expected_args) do [ - 'PUT', - 'foo/_doc/1', - { op_type: 'create' }, - { foo: 'bar' }, - {} + 'PUT', + 'foo/_doc/1', + { op_type: 'create' }, + { foo: 'bar' }, + {} ] end @@ -77,14 +74,13 @@ end context 'when an id is not provided' do - let(:expected_args) do [ - 'POST', - 'foo/_doc', - { }, - { foo: 'bar' }, - {} + 'POST', + 'foo/_doc', + {}, + { foo: 'bar' }, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/create_pit_spec.rb b/opensearch-api/spec/opensearch/api/actions/create_pit_spec.rb index 31397f78e..b2596157d 100644 --- a/opensearch-api/spec/opensearch/api/actions/create_pit_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/create_pit_spec.rb @@ -28,31 +28,31 @@ end it 'requires the :index argument' do - expect { + expect do client.create_pit(keep_alive: '1m') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'requires the :index argument' do - expect { + expect do client.create_pit(index: 'movies') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'does not accept unregistered params' do - expect { + expect do client.create_pit(index: 'movies', keep_alive: '1m', something: 42) - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request with all optional params' do expect(client_double.create_pit( - index: %w[movies books], - keep_alive: '1m', - preference: :random, - routing: :route, - expand_wildcards: :open, - allow_partial_pit_creation: false - )).to eq({}) + index: %w[movies books], + keep_alive: '1m', + preference: :random, + routing: :route, + expand_wildcards: :open, + allow_partial_pit_creation: false + )).to eq({}) end end diff --git a/opensearch-api/spec/opensearch/api/actions/delete_all_pits_spec.rb b/opensearch-api/spec/opensearch/api/actions/delete_all_pits_spec.rb index 1329e7f2f..949758f23 100644 --- a/opensearch-api/spec/opensearch/api/actions/delete_all_pits_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/delete_all_pits_spec.rb @@ -24,9 +24,9 @@ end it 'does not accept unregistered params' do - expect { + expect do client.delete_all_pits(something: :else) - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request with all optional params' do diff --git a/opensearch-api/spec/opensearch/api/actions/delete_by_query_spec.rb b/opensearch-api/spec/opensearch/api/actions/delete_by_query_spec.rb index f2233db32..e85f946ca 100644 --- a/opensearch-api/spec/opensearch/api/actions/delete_by_query_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/delete_by_query_spec.rb @@ -27,7 +27,6 @@ require 'spec_helper' describe 'client#delete_by_query' do - let(:expected_args) do [ 'POST', @@ -39,9 +38,9 @@ end it 'requires the :index argument' do - expect { + expect do Class.new { include OpenSearch::API }.new.delete_by_query(body: {}) - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request' do diff --git a/opensearch-api/spec/opensearch/api/actions/delete_document_spec.rb b/opensearch-api/spec/opensearch/api/actions/delete_document_spec.rb index 1dd5c1a9a..7a7da1905 100644 --- a/opensearch-api/spec/opensearch/api/actions/delete_document_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/delete_document_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client#delete' do - let(:expected_args) do [ - 'DELETE', - 'foo/_doc/1', - params, - nil, - {} + 'DELETE', + 'foo/_doc/1', + params, + nil, + {} ] end @@ -47,15 +46,15 @@ end it 'requires the :index argument' do - expect { + expect do client.delete(id: '1') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'requires the :id argument' do - expect { + expect do client.delete(index: 'foo') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request' do @@ -63,7 +62,6 @@ end context 'when url params are provided' do - let(:params) do { routing: 'abc123' } end @@ -74,23 +72,21 @@ end context 'when invalid url params are provided' do - it 'raises an ArgumentError' do - expect { + expect do client.delete(index: 'foo', id: '1', qwertypoiuy: 'asdflkjhg') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end context 'when the url params need to be escaped' do - let(:expected_args) do [ - 'DELETE', - 'foo%5Ebar/_doc/1', - params, - nil, - {} + 'DELETE', + 'foo%5Ebar/_doc/1', + params, + nil, + {} ] end @@ -100,21 +96,19 @@ end context 'when the index is not found' do - before do expect(client).to receive(:perform_request).and_raise(NotFound) end it 'raises the exception' do - expect { + expect do client.delete(index: 'foo', id: 'XXX') - }.to raise_exception(NotFound) + end.to raise_exception(NotFound) end context 'when the :ignore option is provided' do - it 'does not raise the NotFound exception' do - expect(client.delete(index: 'foo', id: 1, ignore: 404)).to eq(false) + expect(client.delete(index: 'foo', id: 1, ignore: 404)).to be(false) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/delete_pit_spec.rb b/opensearch-api/spec/opensearch/api/actions/delete_pit_spec.rb index fc3f55680..748f5c0cc 100644 --- a/opensearch-api/spec/opensearch/api/actions/delete_pit_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/delete_pit_spec.rb @@ -24,15 +24,15 @@ end it 'requires the :body argument' do - expect { + expect do client.delete_pit - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'does not accept unregistered params' do - expect { + expect do client.delete_pit(body: {}, something: :else) - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request with all optional params' do diff --git a/opensearch-api/spec/opensearch/api/actions/delete_script_spec.rb b/opensearch-api/spec/opensearch/api/actions/delete_script_spec.rb index 60cbfb364..9c2c35bff 100644 --- a/opensearch-api/spec/opensearch/api/actions/delete_script_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/delete_script_spec.rb @@ -28,14 +28,13 @@ describe 'client#delete_script' do context 'when lang parameter is not provided' do - let(:expected_args) do [ - 'DELETE', - '_scripts/foo', - {}, - nil, - {} + 'DELETE', + '_scripts/foo', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/exists_document_spec.rb b/opensearch-api/spec/opensearch/api/actions/exists_document_spec.rb index 6b1a61413..7a52a9fa9 100644 --- a/opensearch-api/spec/opensearch/api/actions/exists_document_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/exists_document_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client#exists' do - let(:expected_args) do [ - 'HEAD', - url, - params, - nil, - {} + 'HEAD', + url, + params, + nil, + {} ] end @@ -51,86 +50,80 @@ end it 'requires the :index argument' do - expect { + expect do client.exists(id: '1') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'requires the :id argument' do - expect { + expect do client.exists(index: 'foo') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end context 'when the type parameter is not provided' do - let(:url) do 'foo/_doc/1' end it 'performs the request' do - expect(client_double.exists(index: 'foo', id: '1')).to eq(true) + expect(client_double.exists(index: 'foo', id: '1')).to be(true) end end it 'is aliased to a predicated method' do - expect(client_double.exists?(index: 'foo', id: '1')).to eq(true) + expect(client_double.exists?(index: 'foo', id: '1')).to be(true) end context 'when URL parameters are provided' do - let(:params) do { routing: 'abc123' } end it 'passes the parameters' do - expect(client_double.exists(index: 'foo', id: '1', routing: 'abc123')).to eq(true) + expect(client_double.exists(index: 'foo', id: '1', routing: 'abc123')).to be(true) end end context 'when the request needs to be URL-escaped' do - let(:url) do 'foo%5Ebar/_doc/1' end it 'URL-escapes the characters' do - expect(client_double.exists(index: 'foo^bar', id: '1')).to eq(true) + expect(client_double.exists(index: 'foo^bar', id: '1')).to be(true) end end context 'when the response is 404' do - before do expect(response_double).to receive(:status).and_return(404) end it 'returns false' do - expect(client_double.exists(index: 'foo', id: '1')).to eq(false) + expect(client_double.exists(index: 'foo', id: '1')).to be(false) end end context 'when the response is 404 NotFound' do - before do expect(response_double).to receive(:status).and_raise(StandardError.new('404 NotFound')) end it 'returns false' do - expect(client_double.exists(index: 'foo', id: '1')).to eq(false) + expect(client_double.exists(index: 'foo', id: '1')).to be(false) end end context 'when there are other errors' do - before do expect(response_double).to receive(:status).and_raise(StandardError) end it 'raises the error' do - expect { + expect do client_double.exists(index: 'foo', id: '1') - }.to raise_exception(StandardError) + end.to raise_exception(StandardError) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/explain_document_spec.rb b/opensearch-api/spec/opensearch/api/actions/explain_document_spec.rb index 5bf5f37bd..80f22aabf 100644 --- a/opensearch-api/spec/opensearch/api/actions/explain_document_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/explain_document_spec.rb @@ -56,17 +56,17 @@ end it 'requires the :index argument' do - expect { + expect do client.explain(id: '1') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'requires the :id argument' do - expect { + expect do client.explain(index: 'foo') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end - + it 'performs the request' do expect(client_double.explain(index: 'foo', id: 1, body: {})).to eq({}) end @@ -102,7 +102,7 @@ end it 'URL-escapes the parts' do - expect(client_double.explain(index: 'foo^bar', id: '1', body: { })).to eq({}) + expect(client_double.explain(index: 'foo^bar', id: '1', body: {})).to eq({}) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/field_caps_spec.rb b/opensearch-api/spec/opensearch/api/actions/field_caps_spec.rb index 550e7ecbd..f540425f6 100644 --- a/opensearch-api/spec/opensearch/api/actions/field_caps_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/field_caps_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client#field_caps' do - let(:expected_args) do [ - 'GET', - 'foo/_field_caps', - { fields: 'bar' }, - nil, - {} + 'GET', + 'foo/_field_caps', + { fields: 'bar' }, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/get_all_pits_spec.rb b/opensearch-api/spec/opensearch/api/actions/get_all_pits_spec.rb index 2abfb96ea..427710566 100644 --- a/opensearch-api/spec/opensearch/api/actions/get_all_pits_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/get_all_pits_spec.rb @@ -24,9 +24,9 @@ end it 'does not accept unregistered params' do - expect { + expect do client.get_all_pits(something: :else) - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request with all optional params' do diff --git a/opensearch-api/spec/opensearch/api/actions/get_document_source_spec.rb b/opensearch-api/spec/opensearch/api/actions/get_document_source_spec.rb index 873c2684b..cacee08da 100644 --- a/opensearch-api/spec/opensearch/api/actions/get_document_source_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/get_document_source_spec.rb @@ -27,19 +27,18 @@ require 'spec_helper' describe 'client#get_source' do - let(:expected_args) do [ - 'GET', - url, - params, - nil, - {} + 'GET', + url, + params, + nil, + {} ] end let(:params) do - { } + {} end let(:url) do @@ -51,19 +50,18 @@ end it 'requires the :index argument' do - expect { + expect do client.get_source(id: '1') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'requires the :id argument' do - expect { + expect do client.get_source(index: 'foo') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end context 'when the type parameter is not provided' do - let(:url) do 'foo/_source/1' end @@ -74,7 +72,6 @@ end context 'when URL parameters are provided' do - let(:params) do { routing: 'abc123' } end @@ -85,7 +82,6 @@ end context 'when the request needs to be URL-escaped' do - let(:url) do 'foo%5Ebar/_source/1' end @@ -96,15 +92,14 @@ end context 'when the request raises a NotFound error' do - before do expect(client).to receive(:perform_request).and_raise(NotFound) end it 'raises the error' do - expect { + expect do client.get_source(index: 'foo', id: '1') - }.to raise_exception(NotFound) + end.to raise_exception(NotFound) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/get_document_spec.rb b/opensearch-api/spec/opensearch/api/actions/get_document_spec.rb index feba187fe..b323dbe47 100644 --- a/opensearch-api/spec/opensearch/api/actions/get_document_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/get_document_spec.rb @@ -27,19 +27,18 @@ require 'spec_helper' describe 'client#get' do - let(:expected_args) do [ - 'GET', - url, - params, - nil, - {} + 'GET', + url, + params, + nil, + {} ] end let(:params) do - { } + {} end let(:url) do @@ -51,19 +50,18 @@ end it 'requires the :index argument' do - expect { + expect do client.get(id: '1') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'requires the :id argument' do - expect { + expect do client.get(index: 'foo') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end context 'when the type parameter is not provided' do - let(:url) do 'foo/_doc/1' end @@ -74,7 +72,6 @@ end context 'when URL parameters are provided' do - let(:params) do { routing: 'abc123' } end @@ -85,16 +82,14 @@ end context 'when invalid URL parameters are provided' do - it 'Passes the URL params' do - expect { + expect do client.get(index: 'foo', id: '1', qwert: 'abc123') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end context 'when the request needs to be URL-escaped' do - let(:url) do 'foo%5Ebar/_doc/1' end @@ -105,27 +100,24 @@ end context 'when the request raises a NotFound error' do - before do expect(client).to receive(:perform_request).and_raise(NotFound) end it 'raises an exception' do - expect { + expect do client.get(index: 'foo', id: '1') - }.to raise_exception(NotFound) + end.to raise_exception(NotFound) end context 'when the ignore option is provided' do - context 'when the response is 404' do - let(:params) do { ignore: 404 } end it 'returns false' do - expect(client.get(index: 'foo', id: '1', ignore: 404)).to eq(false) + expect(client.get(index: 'foo', id: '1', ignore: 404)).to be(false) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/get_script_spec.rb b/opensearch-api/spec/opensearch/api/actions/get_script_spec.rb index 1f1c29e0d..e816d9403 100644 --- a/opensearch-api/spec/opensearch/api/actions/get_script_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/get_script_spec.rb @@ -27,19 +27,18 @@ require 'spec_helper' describe 'client#get_script' do - let(:expected_args) do [ - 'GET', - url, - params, - nil, - {} + 'GET', + url, + params, + nil, + {} ] end let(:params) do - { } + {} end let(:url) do @@ -47,7 +46,6 @@ end context 'when the `lang` parameter is specificed' do - let(:params) do { cluster_manager_timeout: '1s' } end diff --git a/opensearch-api/spec/opensearch/api/actions/hashie_spec.rb b/opensearch-api/spec/opensearch/api/actions/hashie_spec.rb index 40937593e..1888d4184 100644 --- a/opensearch-api/spec/opensearch/api/actions/hashie_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/hashie_spec.rb @@ -28,7 +28,6 @@ require 'hashie' describe 'Hashie' do - let(:json) do <<-JSON { diff --git a/opensearch-api/spec/opensearch/api/actions/index_document_spec.rb b/opensearch-api/spec/opensearch/api/actions/index_document_spec.rb index 6f9c60f52..914fce96b 100644 --- a/opensearch-api/spec/opensearch/api/actions/index_document_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/index_document_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client#index' do - let(:expected_args) do [ - request_type, - url, - params, - body, - {} + request_type, + url, + params, + body, + {} ] end @@ -43,7 +42,7 @@ end let(:params) do - { } + {} end let(:url) do @@ -59,9 +58,9 @@ end it 'requires the :index argument' do - expect { - client.index() - }.to raise_exception(ArgumentError) + expect do + client.index + end.to raise_exception(ArgumentError) end it 'performs the request' do @@ -69,7 +68,6 @@ end context 'when a specific id is provided' do - let(:request_type) do 'PUT' end @@ -84,7 +82,6 @@ end context 'when URL parameters are provided' do - let(:request_type) do 'POST' end @@ -102,7 +99,6 @@ end context 'when a specific id is provided' do - let(:request_type) do 'PUT' end @@ -136,11 +132,10 @@ end context 'when an invalid URL parameter is provided' do - it 'raises and ArgumentError' do - expect { + expect do client.index(index: 'foo', id: '1', qwerty: 'yuiop') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/add_block_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/add_block_spec.rb index 7d59d33c4..0dfdcbfa0 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/add_block_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/add_block_spec.rb @@ -36,7 +36,7 @@ {} ] end - let(:url) { "#{index}/_block/#{block}"} + let(:url) { "#{index}/_block/#{block}" } let(:index) { 'test_index' } let(:block) { 'test_block' } diff --git a/opensearch-api/spec/opensearch/api/actions/indices/clear_cache_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/clear_cache_spec.rb index 016a39228..203c72806 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/clear_cache_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/clear_cache_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.indices#clear_cache' do - let(:expected_args) do [ - 'POST', - url, - params, - nil, - {} + 'POST', + url, + params, + nil, + {} ] end @@ -51,7 +50,6 @@ end context 'when an index is specified' do - let(:url) do 'foo/_cache/clear' end @@ -62,7 +60,6 @@ end context 'when params are specified' do - let(:params) do { fielddata: true } end @@ -73,13 +70,12 @@ end context 'when the path must be URL-escaped' do - let(:url) do 'foo%5Ebar/_cache/clear' end let(:params) do - { } + {} end it 'performs the request' do diff --git a/opensearch-api/spec/opensearch/api/actions/indices/clone_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/clone_spec.rb index 95ecefc97..6bda2a5f6 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/clone_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/clone_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.indices#clone' do - let(:expected_args) do [ - 'PUT', - url, - params, - body, - {} + 'PUT', + url, + params, + body, + {} ] end @@ -51,45 +50,41 @@ end context 'when there is no index specified' do - let(:client) do Class.new { include OpenSearch::API }.new end it 'raises an exception' do - expect { + expect do client.indices.clone(target: 'my_target_index') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end context 'when there is no index specified' do - let(:client) do Class.new { include OpenSearch::API }.new end it 'raises an exception' do - expect { + expect do client.indices.clone(index: 'my_source_index') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end context 'when an index and target are specified' do - it 'performs the request' do expect(client_double.indices.clone(index: 'my_source_index', target: 'my_target_index')).to eq({}) end end context 'when params are provided' do - let(:params) do { - timeout: '1s', - cluster_manager_timeout: '10s', - wait_for_active_shards: 1 + timeout: '1s', + cluster_manager_timeout: '10s', + wait_for_active_shards: 1 } end @@ -103,15 +98,14 @@ end context 'when a body is specified' do - let(:body) do { - settings: { - 'index.number_of_shards' => 5 - }, - aliases: { - my_search_indices: {} - } + settings: { + 'index.number_of_shards' => 5 + }, + aliases: { + my_search_indices: {} + } } end @@ -119,12 +113,12 @@ expect(client_double.indices.clone(index: 'my_source_index', target: 'my_target_index', body: { - settings: { - 'index.number_of_shards' => 5 - }, - aliases: { - my_search_indices: {} - } + settings: { + 'index.number_of_shards' => 5 + }, + aliases: { + my_search_indices: {} + } })).to eq({}) end end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/close_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/close_spec.rb index a529bfa36..c8fdf1ba6 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/close_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/close_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.indices#close' do - let(:expected_args) do [ - 'POST', - url, - params, - nil, - {} + 'POST', + url, + params, + nil, + {} ] end @@ -43,20 +42,18 @@ end context 'when there is no index specified' do - let(:client) do Class.new { include OpenSearch::API }.new end it 'raises an exception' do - expect { + expect do client.indices.close - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end context 'when an index is specified' do - let(:url) do 'foo/_close' end @@ -67,7 +64,6 @@ end context 'when params are specified' do - let(:params) do { timeout: '1s' } end @@ -82,7 +78,6 @@ end context 'when the path must be URL-escaped' do - let(:url) do 'foo%5Ebar/_close' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/create_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/create_spec.rb index 754ec288f..34ad6570c 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/create_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/create_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.indices#create' do - let(:expected_args) do [ - 'PUT', - url, - params, - nil, - {} + 'PUT', + url, + params, + nil, + {} ] end @@ -43,20 +42,18 @@ end context 'when there is no index specified' do - let(:client) do Class.new { include OpenSearch::API }.new end it 'raises an exception' do - expect { + expect do client.indices.create - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end context 'when an index is specified' do - let(:url) do 'foo' end @@ -67,7 +64,6 @@ end context 'when params are specified' do - let(:params) do { timeout: '1s' } end @@ -82,7 +78,6 @@ end context 'when the path must be URL-escaped' do - let(:url) do 'foo%5Ebar' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/delete_alias_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/delete_alias_spec.rb index 727cb75d6..a7948ba43 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/delete_alias_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/delete_alias_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.indices#delete_alias' do - let(:expected_args) do [ - 'DELETE', - url, - params, - nil, - {} + 'DELETE', + url, + params, + nil, + {} ] end @@ -43,33 +42,30 @@ end context 'when there is no index specified' do - let(:client) do Class.new { include OpenSearch::API }.new end it 'raises an exception' do - expect { + expect do client.indices.delete_alias(name: 'foo') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end context 'when there is no name specified' do - let(:client) do Class.new { include OpenSearch::API }.new end it 'raises an exception' do - expect { + expect do client.indices.delete_alias(index: 'foo') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end context 'when an index and name are specified' do - let(:url) do 'foo/_aliases/bar' end @@ -80,7 +76,6 @@ end context 'when the path must be URL-escaped' do - let(:url) do 'foo%5Ebar/_aliases/bar%2Fbam' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/delete_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/delete_spec.rb index 6f67cb3fd..80698ec3b 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/delete_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/delete_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.indices#delete' do - let(:expected_args) do [ - 'DELETE', - url, - params, - nil, - {} + 'DELETE', + url, + params, + nil, + {} ] end @@ -51,18 +50,16 @@ end context 'when more than one index is specified' do - let(:url) do 'foo,bar' end it 'performs the request' do - expect(client_double.indices.delete(index: ['foo', 'bar'])).to eq({}) + expect(client_double.indices.delete(index: %w[foo bar])).to eq({}) end end context 'when params are specified' do - let(:params) do { timeout: '1s' } end @@ -73,7 +70,6 @@ end context 'when the path must be URL-escaped' do - let(:url) do 'foo%5Ebar' end @@ -84,7 +80,6 @@ end context 'when a NotFound exception is raised by the request' do - let(:client) do Class.new { include OpenSearch::API }.new end @@ -94,14 +89,13 @@ end it 'raises the exception' do - expect { + expect do client.indices.delete(index: 'foo') - }.to raise_exception(NotFound) + end.to raise_exception(NotFound) end end context 'when the ignore parameter is specified' do - let(:client) do Class.new { include OpenSearch::API }.new end @@ -111,7 +105,7 @@ end it 'ignores the code' do - expect(client.indices.delete(index: 'foo', ignore: 404)).to eq(false) + expect(client.indices.delete(index: 'foo', ignore: 404)).to be(false) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/delete_template_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/delete_template_spec.rb index 66ca538ee..b95bc1585 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/delete_template_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/delete_template_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.indices#delete_template' do - let(:expected_args) do [ - 'DELETE', - url, - params, - nil, - {} + 'DELETE', + url, + params, + nil, + {} ] end @@ -51,7 +50,6 @@ end context 'when the path needs to be URL-escaped' do - let(:url) do '_template/foo%5Ebar' end @@ -62,7 +60,6 @@ end context 'when a NotFound exception is raised by the request' do - let(:client) do Class.new { include OpenSearch::API }.new end @@ -72,14 +69,13 @@ end it 'raises the exception' do - expect { + expect do client.indices.delete_template(name: 'foo') - }.to raise_exception(NotFound) + end.to raise_exception(NotFound) end end context 'when the ignore parameter is specified' do - let(:client) do Class.new { include OpenSearch::API }.new end @@ -89,7 +85,7 @@ end it 'ignores the code' do - expect(client.indices.delete_template(name: 'foo', ignore: 404)).to eq(false) + expect(client.indices.delete_template(name: 'foo', ignore: 404)).to be(false) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/exists_alias_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/exists_alias_spec.rb index 7e1da844d..ddb6758a2 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/exists_alias_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/exists_alias_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.indices#exists_alias' do - let(:expected_args) do [ - 'HEAD', - url, - params, - nil, - {} + 'HEAD', + url, + params, + nil, + {} ] end @@ -47,48 +46,44 @@ end it 'performs the request' do - expect(client_double.indices.exists_alias(name: 'foo')).to eq(true) + expect(client_double.indices.exists_alias(name: 'foo')).to be(true) end it 'aliased to a predicate method' do - expect(client_double.indices.exists_alias?(name: 'foo')).to eq(true) + expect(client_double.indices.exists_alias?(name: 'foo')).to be(true) end context 'when multiple indices are specified' do - let(:url) do 'foo,bar/_alias/bam' end it 'performs the request' do - expect(client_double.indices.exists_alias(index: ['foo','bar'], name: 'bam')).to eq(true) + expect(client_double.indices.exists_alias(index: %w[foo bar], name: 'bam')).to be(true) end end context 'when the path needs to be URL-escaped' do - let(:url) do 'foo%5Ebar/_alias/bar%2Fbam' end it 'performs the request' do - expect(client_double.indices.exists_alias(index: 'foo^bar', name: 'bar/bam')).to eq(true) + expect(client_double.indices.exists_alias(index: 'foo^bar', name: 'bar/bam')).to be(true) end end context 'when 404 response is received' do - let(:response_double) do double('response', status: 404, body: {}, headers: {}) end it 'returns false' do - expect(client_double.indices.exists_alias(name: 'foo')).to eq(false) + expect(client_double.indices.exists_alias(name: 'foo')).to be(false) end end context 'when a \'not found\' exception is raised' do - let(:client) do Class.new { include OpenSearch::API }.new.tap do |_client| expect(_client).to receive(:perform_request).with(*expected_args).and_raise(StandardError.new('404 Not Found')) @@ -96,12 +91,11 @@ end it 'returns false' do - expect(client.indices.exists_alias(name: 'foo')).to eq(false) + expect(client.indices.exists_alias(name: 'foo')).to be(false) end end context 'when a generic exception is raised' do - let(:client) do Class.new { include OpenSearch::API }.new.tap do |_client| expect(_client).to receive(:perform_request).with(*expected_args).and_raise(StandardError.new) @@ -109,9 +103,9 @@ end it 'raises the exception' do - expect { + expect do client.indices.exists_alias(name: 'foo') - }.to raise_exception(StandardError) + end.to raise_exception(StandardError) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/exists_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/exists_spec.rb index 77584435c..0cb9b37cb 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/exists_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/exists_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.indices#exists' do - let(:expected_args) do [ - 'HEAD', - url, - params, - nil, - {} + 'HEAD', + url, + params, + nil, + {} ] end @@ -47,48 +46,44 @@ end it 'performs the request' do - expect(client_double.indices.exists(index: 'foo')).to eq(true) + expect(client_double.indices.exists(index: 'foo')).to be(true) end it 'aliased to a predicate method' do - expect(client_double.indices.exists?(index: 'foo')).to eq(true) + expect(client_double.indices.exists?(index: 'foo')).to be(true) end context 'when multiple indices are specified' do - let(:url) do 'foo,bar' end it 'performs the request' do - expect(client_double.indices.exists(index: ['foo','bar'])).to eq(true) + expect(client_double.indices.exists(index: %w[foo bar])).to be(true) end end context 'when the path needs to be URL-escaped' do - let(:url) do 'foo%5Ebar' end it 'performs the request' do - expect(client_double.indices.exists(index: 'foo^bar')).to eq(true) + expect(client_double.indices.exists(index: 'foo^bar')).to be(true) end end context 'when 404 response is received' do - let(:response_double) do double('response', status: 404, body: {}, headers: {}) end it 'returns false' do - expect(client_double.indices.exists(index: 'foo')).to eq(false) + expect(client_double.indices.exists(index: 'foo')).to be(false) end end context 'when a \'not found\' exception is raised' do - let(:client) do Class.new { include OpenSearch::API }.new.tap do |_client| expect(_client).to receive(:perform_request).with(*expected_args).and_raise(StandardError.new('404 Not Found')) @@ -96,12 +91,11 @@ end it 'returns false' do - expect(client.indices.exists(index: 'foo')).to eq(false) + expect(client.indices.exists(index: 'foo')).to be(false) end end context 'when a generic exception is raised' do - let(:client) do Class.new { include OpenSearch::API }.new.tap do |_client| expect(_client).to receive(:perform_request).with(*expected_args).and_raise(StandardError.new) @@ -109,9 +103,9 @@ end it 'raises the exception' do - expect { + expect do client.indices.exists(index: 'foo') - }.to raise_exception(StandardError) + end.to raise_exception(StandardError) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/exists_template_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/exists_template_spec.rb index 75894ba6d..7ea90056a 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/exists_template_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/exists_template_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.indices#exists_template' do - let(:expected_args) do [ - 'HEAD', - url, - params, - nil, - {} + 'HEAD', + url, + params, + nil, + {} ] end @@ -47,33 +46,30 @@ end it 'performs the request' do - expect(client_double.indices.exists_template(name: 'foo')).to eq(true) + expect(client_double.indices.exists_template(name: 'foo')).to be(true) end context 'when the path needs to be URL-escaped' do - let(:url) do '_template/bar%2Fbam' end it 'performs the request' do - expect(client_double.indices.exists_template(name: 'bar/bam')).to eq(true) + expect(client_double.indices.exists_template(name: 'bar/bam')).to be(true) end end context 'when 404 response is received' do - let(:response_double) do double('response', status: 404, body: {}, headers: {}) end it 'returns false' do - expect(client_double.indices.exists_template(name: 'foo')).to eq(false) + expect(client_double.indices.exists_template(name: 'foo')).to be(false) end end context 'when a \'not found\' exception is raised' do - let(:client) do Class.new { include OpenSearch::API }.new.tap do |_client| expect(_client).to receive(:perform_request).with(*expected_args).and_raise(StandardError.new('404 Not Found')) @@ -81,12 +77,11 @@ end it 'returns false' do - expect(client.indices.exists_template(name: 'foo')).to eq(false) + expect(client.indices.exists_template(name: 'foo')).to be(false) end end context 'when a generic exception is raised' do - let(:client) do Class.new { include OpenSearch::API }.new.tap do |_client| expect(_client).to receive(:perform_request).with(*expected_args).and_raise(StandardError.new) @@ -94,9 +89,9 @@ end it 'raises the exception' do - expect { + expect do client.indices.exists_template(name: 'foo') - }.to raise_exception(StandardError) + end.to raise_exception(StandardError) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/field_usage_stats_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/field_usage_stats_spec.rb index 321be311e..08e5bd5be 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/field_usage_stats_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/field_usage_stats_spec.rb @@ -47,9 +47,9 @@ end it 'raises an exception' do - expect { + expect do client.indices.field_usage_stats - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/flush_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/flush_spec.rb index 94f0b169d..373c68c04 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/flush_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/flush_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.indices#flush' do - let(:expected_args) do [ - 'POST', - url, - params, - nil, - {} + 'POST', + url, + params, + nil, + {} ] end @@ -51,7 +50,6 @@ end context 'when an index is specified' do - let(:url) do 'foo/_flush' end @@ -62,18 +60,16 @@ end context 'when multiple indices are specified' do - let(:url) do 'foo,bar/_flush' end it 'performs the request' do - expect(client_double.indices.flush(index: ['foo','bar'])).to eq({}) + expect(client_double.indices.flush(index: %w[foo bar])).to eq({}) end end context 'when the path needs to be URL-escaped' do - let(:url) do 'foo%5Ebar/_flush' end @@ -84,7 +80,6 @@ end context 'when URL parameters are specified' do - let(:url) do 'foo/_flush' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/forcemerge_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/forcemerge_spec.rb index 3bf4c3d97..392241aa0 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/forcemerge_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/forcemerge_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#forcemerge' do - let(:expected_args) do [ - 'POST', - '_forcemerge', - {}, - nil, - {} + 'POST', + '_forcemerge', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/get_alias_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/get_alias_spec.rb index 6897fc3b7..9d6dbe559 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/get_alias_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/get_alias_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#get_alias' do - let(:expected_args) do [ - 'GET', - url, - {}, - nil, - {} + 'GET', + url, + {}, + nil, + {} ] end @@ -47,18 +46,16 @@ end context 'when multiple indices are specified' do - let(:url) do 'foo,bar/_alias/bam' end it 'performs the request' do - expect(client_double.indices.get_alias(index: ['foo','bar'], name: 'bam')).to eq({}) + expect(client_double.indices.get_alias(index: %w[foo bar], name: 'bam')).to eq({}) end end context 'when the path needs to be URL-escaped' do - let(:url) do 'foo%5Ebar/_alias/bar%2Fbam' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/get_field_mapping_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/get_field_mapping_spec.rb index 1071af6a8..edbceaf81 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/get_field_mapping_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/get_field_mapping_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#get_field_mapping' do - let(:expected_args) do [ - 'GET', - url, - {}, - nil, - {} + 'GET', + url, + {}, + nil, + {} ] end @@ -47,7 +46,6 @@ end context 'when an index is specified' do - let(:url) do 'foo/_mapping/field/bam' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/get_mapping_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/get_mapping_spec.rb index 1d814d077..8a9c01164 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/get_mapping_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/get_mapping_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#get_mapping' do - let(:expected_args) do [ - 'GET', - url, - {}, - nil, - {} + 'GET', + url, + {}, + nil, + {} ] end @@ -47,7 +46,6 @@ end context 'when an index is specified' do - let(:url) do 'foo/_mapping' end @@ -58,18 +56,16 @@ end context 'when multiple indices are specified' do - let(:url) do 'foo,bar/_mapping' end it 'performs the request' do - expect(client_double.indices.get_mapping(index: ['foo', 'bar'])).to eq({}) + expect(client_double.indices.get_mapping(index: %w[foo bar])).to eq({}) end end context 'when the path must be URL-escaped' do - let(:url) do 'foo%5Ebar/_mapping' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/get_settings_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/get_settings_spec.rb index ff958b487..0cd15242f 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/get_settings_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/get_settings_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#get_settings' do - let(:expected_args) do [ - 'GET', - url, - {}, - nil, - {} + 'GET', + url, + {}, + nil, + {} ] end @@ -47,7 +46,6 @@ end context 'when an index is specified' do - let(:url) do 'foo/_settings' end @@ -58,7 +56,6 @@ end context 'when a name is specified' do - let(:url) do 'foo/_settings/foo.bar' end @@ -69,7 +66,6 @@ end context 'when the path must be URL-escaped' do - let(:url) do 'foo%5Ebar/_settings' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/get_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/get_spec.rb index 7db0d8521..1eb4a4946 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/get_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/get_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.indices#get' do - let(:expected_args) do [ - 'GET', - url, - params, - nil, - {} + 'GET', + url, + params, + nil, + {} ] end @@ -51,7 +50,6 @@ end context 'when parameters are specified' do - let(:params) do { ignore_unavailable: 1 } end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/open_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/open_spec.rb index 3fd6d593e..94b3f561b 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/open_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/open_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.indices#open' do - let(:expected_args) do [ - 'POST', - url, - params, - nil, - {} + 'POST', + url, + params, + nil, + {} ] end @@ -51,7 +50,6 @@ end context 'when parameters are specified' do - let(:params) do { timeout: '1s' } end @@ -62,7 +60,6 @@ end context 'when the path must be URL-escaped' do - let(:url) do 'foo%5Ebar/_open' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/put_alias_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/put_alias_spec.rb index 4f6136d13..3712b3a64 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/put_alias_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/put_alias_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#put_alias' do - let(:expected_args) do [ - 'PUT', - url, - {}, - body, - {} + 'PUT', + url, + {}, + body, + {} ] end @@ -51,20 +50,18 @@ end context 'when there is no name specified' do - let(:client) do Class.new { include OpenSearch::API }.new end it 'raises an exception' do - expect { + expect do client.indices.put_alias(name: 'foo') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end context 'when a body is specified' do - let(:body) do { filter: 'foo' } end @@ -75,18 +72,16 @@ end context 'when multiple indices are specified' do - let(:url) do 'foo,bar/_aliases/bam' end it 'performs the request' do - expect(client_double.indices.put_alias(index: ['foo','bar'], name: 'bam')).to eq({}) + expect(client_double.indices.put_alias(index: %w[foo bar], name: 'bam')).to eq({}) end end context 'when the path needs to be URL-escaped' do - let(:url) do 'foo%5Ebar/_aliases/bar%2Fbam' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/put_mapping_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/put_mapping_spec.rb index bca2ebccf..c14399d97 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/put_mapping_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/put_mapping_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#put_mapping' do - let(:expected_args) do [ - 'PUT', - url, - {}, - body, - {} + 'PUT', + url, + {}, + body, + {} ] end @@ -51,20 +50,18 @@ end context 'when there is no body specified' do - let(:client) do Class.new { include OpenSearch::API }.new end it 'raises an exception' do - expect { + expect do client.indices.put_mapping(index: 'foo') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end context 'when a body is specified' do - let(:body) do { filter: 'foo' } end @@ -75,18 +72,16 @@ end context 'when multiple indices are specified' do - let(:url) do 'foo,bar/_mappings' end it 'performs the request' do - expect(client_double.indices.put_mapping(index: ['foo','bar'], body: {})).to eq({}) + expect(client_double.indices.put_mapping(index: %w[foo bar], body: {})).to eq({}) end end context 'when the path needs to be URL-escaped' do - let(:url) do 'foo%5Ebar/_mappings' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/put_settings_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/put_settings_spec.rb index f10c40f67..cd28dd8e1 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/put_settings_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/put_settings_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#put_settings' do - let(:expected_args) do [ - 'PUT', - url, - params, - body, - {} + 'PUT', + url, + params, + body, + {} ] end @@ -55,20 +54,18 @@ end context 'when there is no body specified' do - let(:client) do Class.new { include OpenSearch::API }.new end it 'raises an exception' do - expect { + expect do client.indices.put_settings - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end context 'when parameters are specified' do - let(:params) do { flat_settings: true } end @@ -83,7 +80,6 @@ end context 'when an index is specified' do - let(:url) do 'foo/_settings' end @@ -94,18 +90,16 @@ end context 'when multiple indices are specified' do - let(:url) do 'foo,bar/_settings' end it 'performs the request' do - expect(client_double.indices.put_settings(index: ['foo','bar'], body: {})).to eq({}) + expect(client_double.indices.put_settings(index: %w[foo bar], body: {})).to eq({}) end end context 'when the path needs to be URL-escaped' do - let(:url) do 'foo%5Ebar/_settings' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/put_template_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/put_template_spec.rb index 64a3b72bb..bb0dea5dd 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/put_template_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/put_template_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#put_template' do - let(:expected_args) do [ - 'PUT', - url, - params, - body, - {} + 'PUT', + url, + params, + body, + {} ] end @@ -55,33 +54,30 @@ end context 'when there is no name specified' do - let(:client) do Class.new { include OpenSearch::API }.new end it 'raises an exception' do - expect { + expect do client.indices.put_template(body: {}) - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end context 'when there is no body specified' do - let(:client) do Class.new { include OpenSearch::API }.new end it 'raises an exception' do - expect { + expect do client.indices.put_template(name: 'foo') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end context 'when parameters are specified' do - let(:params) do { order: 3 } end @@ -100,7 +96,6 @@ end context 'when the path needs to be URL-escaped' do - let(:url) do '_template/foo%5Ebar' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/recovery_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/recovery_spec.rb index 3889ffb97..db924d58f 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/recovery_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/recovery_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#recovery' do - let(:expected_args) do [ - 'GET', - 'foo/_recovery', - {}, - nil, - {} + 'GET', + 'foo/_recovery', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/refresh_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/refresh_spec.rb index 19a63ea86..3c7cefc9b 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/refresh_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/refresh_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#refresh' do - let(:expected_args) do [ - 'POST', - url, - params, - body, - {} + 'POST', + url, + params, + body, + {} ] end @@ -55,7 +54,6 @@ end context 'when an index is specified' do - let(:url) do 'foo/_refresh' end @@ -66,18 +64,16 @@ end context 'when multiple indicies are specified as a list' do - let(:url) do 'foo,bar/_refresh' end it 'performs the request' do - expect(client_double.indices.refresh(index: ['foo', 'bar'])).to eq({}) + expect(client_double.indices.refresh(index: %w[foo bar])).to eq({}) end end context 'when multiple indicies are specified as a string' do - let(:url) do 'foo,bar/_refresh' end @@ -88,7 +84,6 @@ end context 'when the path needs to be URL-escaped' do - let(:url) do 'foo%5Ebar/_refresh' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/rollover_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/rollover_spec.rb index c77e9e6ca..03507ef3e 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/rollover_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/rollover_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#rollover' do - let(:expected_args) do [ - 'POST', - url, - params, - body, - {} + 'POST', + url, + params, + body, + {} ] end @@ -55,7 +54,6 @@ end context 'when an index is specified' do - let(:url) do 'foo/_rollover/bar' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/segments_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/segments_spec.rb index da6da4bd9..0749ecc13 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/segments_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/segments_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#segments' do - let(:expected_args) do [ - 'GET', - url, - params, - body, - {} + 'GET', + url, + params, + body, + {} ] end @@ -55,7 +54,6 @@ end context 'when an index is specified' do - let(:url) do 'foo/_segments' end @@ -66,18 +64,16 @@ end context 'when multiple indicies are specified as a list' do - let(:url) do 'foo,bar/_segments' end it 'performs the request' do - expect(client_double.indices.segments(index: ['foo', 'bar'])).to eq({}) + expect(client_double.indices.segments(index: %w[foo bar])).to eq({}) end end context 'when multiple indicies are specified as a string' do - let(:url) do 'foo,bar/_segments' end @@ -88,7 +84,6 @@ end context 'when the path needs to be URL-escaped' do - let(:url) do 'foo%5Ebar/_segments' end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/shard_stores_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/shard_stores_spec.rb index 8498c9af6..662994e92 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/shard_stores_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/shard_stores_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#shard_stores' do - let(:expected_args) do [ - 'GET', - '_shard_stores', - {}, - nil, - {} + 'GET', + '_shard_stores', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/shrink_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/shrink_spec.rb index f0cdf46ea..0b11a622e 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/shrink_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/shrink_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#shrink' do - let(:expected_args) do [ - 'PUT', - 'foo/_shrink/bar', - {}, - nil, - {} + 'PUT', + 'foo/_shrink/bar', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/split_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/split_spec.rb index 74b7b0abb..52e3cd855 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/split_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/split_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#split' do - let(:expected_args) do [ - 'PUT', - 'foo/_split/bar', - {}, - nil, - {} + 'PUT', + 'foo/_split/bar', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/stats_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/stats_spec.rb index 3c328229c..6088cd465 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/stats_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/stats_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#stats' do - let(:expected_args) do [ - 'GET', - url, - params, - body, - {} + 'GET', + url, + params, + body, + {} ] end @@ -55,7 +54,6 @@ end context 'when an index is specified' do - let(:url) do 'foo/_stats' end @@ -66,18 +64,16 @@ end context 'when multiple indicies are specified as a list' do - let(:url) do 'foo,bar/_stats' end it 'performs the request' do - expect(client_double.indices.stats(index: ['foo', 'bar'])).to eq({}) + expect(client_double.indices.stats(index: %w[foo bar])).to eq({}) end end context 'when multiple indicies are specified as a string' do - let(:url) do 'foo,bar/_stats' end @@ -102,7 +98,6 @@ end context 'when the fields parameter is specified as a list' do - let(:params) do { fields: 'foo,bar' } end @@ -112,12 +107,11 @@ end it 'performs the request' do - expect(client_double.indices.stats(index: 'foo', fielddata: true, fields: [ 'foo', 'bar'])).to eq({}) + expect(client_double.indices.stats(index: 'foo', fielddata: true, fields: %w[foo bar])).to eq({}) end end context 'when the groups parameter is specified as a list' do - let(:params) do { groups: 'groupA,groupB' } end @@ -127,7 +121,7 @@ end it 'performs the request' do - expect(client_double.indices.stats(search: true, groups: [ 'groupA', 'groupB'])).to eq({}) + expect(client_double.indices.stats(search: true, groups: %w[groupA groupB])).to eq({}) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/update_aliases_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/update_aliases_spec.rb index 5423e4361..429544867 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/update_aliases_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/update_aliases_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#update_aliases' do - let(:expected_args) do [ - 'POST', - '_aliases', - params, - body, - {} + 'POST', + '_aliases', + params, + body, + {} ] end @@ -51,20 +50,18 @@ end context 'when a body is not specified' do - let(:client) do Class.new { include OpenSearch::API }.new end it 'raises an exception' do - expect { + expect do client.indices.update_aliases - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end context 'when parameters are specified' do - let(:params) do { timeout: '1s' } end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/upgrade_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/upgrade_spec.rb index 03c28ddfb..3450af2f0 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/upgrade_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/upgrade_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.cluster#upgrade' do - let(:expected_args) do [ - 'POST', - '_upgrade', - {}, - nil, - {} + 'POST', + '_upgrade', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/indices/validate_query_spec.rb b/opensearch-api/spec/opensearch/api/actions/indices/validate_query_spec.rb index 583d0711c..e38d5c1ea 100644 --- a/opensearch-api/spec/opensearch/api/actions/indices/validate_query_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/indices/validate_query_spec.rb @@ -70,7 +70,7 @@ end it 'performs the request' do - expect(client_double.indices.validate_query(index: ['foo', 'bar'])).to eq({}) + expect(client_double.indices.validate_query(index: %w[foo bar])).to eq({}) end end diff --git a/opensearch-api/spec/opensearch/api/actions/info_spec.rb b/opensearch-api/spec/opensearch/api/actions/info_spec.rb index 0d5cbd108..5fc4f204e 100644 --- a/opensearch-api/spec/opensearch/api/actions/info_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/info_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client#info' do - let(:expected_args) do [ - 'GET', - '', - { }, - nil, - {} + 'GET', + '', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/ingest/delete_pipeline_spec.rb b/opensearch-api/spec/opensearch/api/actions/ingest/delete_pipeline_spec.rb index b7ca9651d..09e0e89ae 100644 --- a/opensearch-api/spec/opensearch/api/actions/ingest/delete_pipeline_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/ingest/delete_pipeline_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.ingest#delete_pipeline' do - let(:expected_args) do [ - 'DELETE', - url, - {}, - nil, - {} + 'DELETE', + url, + {}, + nil, + {} ] end @@ -47,9 +46,9 @@ end it 'requires the :id argument' do - expect { + expect do client.ingest.delete_pipeline - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request' do @@ -57,7 +56,6 @@ end context 'when the path must be URL-escaped' do - let(:url) do '_ingest/pipeline/foo%5Ebar' end diff --git a/opensearch-api/spec/opensearch/api/actions/ingest/get_pipeline_spec.rb b/opensearch-api/spec/opensearch/api/actions/ingest/get_pipeline_spec.rb index b68a6e942..94a1f9f53 100644 --- a/opensearch-api/spec/opensearch/api/actions/ingest/get_pipeline_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/ingest/get_pipeline_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.ingest#get_pipeline' do - let(:expected_args) do [ - 'GET', - url, - {}, - nil, - {} + 'GET', + url, + {}, + nil, + {} ] end @@ -47,7 +46,6 @@ end context 'when the path must be URL-escaped' do - let(:url) do '_ingest/pipeline/foo%5Ebar' end diff --git a/opensearch-api/spec/opensearch/api/actions/ingest/put_pipeline_spec.rb b/opensearch-api/spec/opensearch/api/actions/ingest/put_pipeline_spec.rb index dd515f200..1c111b538 100644 --- a/opensearch-api/spec/opensearch/api/actions/ingest/put_pipeline_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/ingest/put_pipeline_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.ingest#put_pipeline' do - let(:expected_args) do [ - 'PUT', - url, - {}, - {}, - {} + 'PUT', + url, + {}, + {}, + {} ] end @@ -47,9 +46,9 @@ end it 'requires the :id argument' do - expect { + expect do client.ingest.put_pipeline - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request' do @@ -57,7 +56,6 @@ end context 'when the path must be URL-escaped' do - let(:url) do '_ingest/pipeline/foo%5Ebar' end diff --git a/opensearch-api/spec/opensearch/api/actions/mget_spec.rb b/opensearch-api/spec/opensearch/api/actions/mget_spec.rb index b66025f79..4245fb8ed 100644 --- a/opensearch-api/spec/opensearch/api/actions/mget_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/mget_spec.rb @@ -50,22 +50,20 @@ end it 'performs the request' do - expect(client_double.mget(body: { :docs => [] })).to eq({}) + expect(client_double.mget(body: { docs: [] })).to eq({}) end context 'when an index is specified' do - let(:url) do 'foo/_mget' end it 'performs the request' do - expect(client_double.mget(index: 'foo', body: { :docs => [] })).to eq({}) + expect(client_double.mget(index: 'foo', body: { docs: [] })).to eq({}) end end context 'when url parameters are provided' do - let(:params) do { refresh: true } end @@ -80,17 +78,16 @@ end context 'when the request needs to be URL-escaped' do - let(:url) do 'foo%5Ebar/_mget' end let(:body) do - { ids: [ '1', '2' ]} + { ids: %w[1 2] } end it 'performs the request' do - expect(client_double.mget(index: 'foo^bar', body: { :ids => [ '1', '2'] })).to eq({}) + expect(client_double.mget(index: 'foo^bar', body: { ids: %w[1 2] })).to eq({}) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/msearch_spec.rb b/opensearch-api/spec/opensearch/api/actions/msearch_spec.rb index 57e28cc77..eb0d72049 100644 --- a/opensearch-api/spec/opensearch/api/actions/msearch_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/msearch_spec.rb @@ -79,7 +79,7 @@ expect( client_double.msearch( body: [ - { index: 'foo', search: { query: { match_all: {} } } }, + { index: 'foo', search: { query: { match_all: {} } } }, { index: 'bar', search: { query: { match: { foo: 'bar' } } } }, { search_type: 'count', search: { facets: { tags: {} } } } ] @@ -90,11 +90,11 @@ context 'when the body is a string' do let(:body) do - %Q|{"foo":"bar"}\n{"moo":"lam"}| + %({"foo":"bar"}\n{"moo":"lam"}) end it 'performs the request' do - expect(client_double.msearch(body: %Q|{"foo":"bar"}\n{"moo":"lam"}|)).to eq({}) + expect(client_double.msearch(body: %({"foo":"bar"}\n{"moo":"lam"}))).to eq({}) end end @@ -122,7 +122,7 @@ end it 'performs the request' do - expect(client_double.msearch(index: ['foo', 'bar'], body: [])) + expect(client_double.msearch(index: %w[foo bar], body: [])) end end diff --git a/opensearch-api/spec/opensearch/api/actions/msearch_template_spec.rb b/opensearch-api/spec/opensearch/api/actions/msearch_template_spec.rb index 5827754fc..23f46faa2 100644 --- a/opensearch-api/spec/opensearch/api/actions/msearch_template_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/msearch_template_spec.rb @@ -54,7 +54,6 @@ end context 'when a body is provided as a document' do - let(:body) do <<-PAYLOAD.gsub(/^\s+/, '') {"index":"foo"} @@ -66,27 +65,25 @@ it 'performs the request' do expect(client_double.msearch_template(body: [ - { index: 'foo' }, - { inline: { query: { match: { foo: '{{q}}' } } }, params: { q: 'foo' } }, - { index: 'bar' }, - { id: 'query_foo', params: { q: 'foo' } } - ])).to eq({}) + { index: 'foo' }, + { inline: { query: { match: { foo: '{{q}}' } } }, params: { q: 'foo' } }, + { index: 'bar' }, + { id: 'query_foo', params: { q: 'foo' } } + ])).to eq({}) end end context 'when a body is provided as a string' do - let(:body) do - %Q|{"foo":"bar"}\n{"moo":"lam"}| + %({"foo":"bar"}\n{"moo":"lam"}) end it 'performs the request' do - expect(client_double.msearch_template(body: %Q|{"foo":"bar"}\n{"moo":"lam"}|)).to eq({}) + expect(client_double.msearch_template(body: %({"foo":"bar"}\n{"moo":"lam"}))).to eq({}) end end context 'when an index is provided' do - let(:url) do 'foo/_msearch/template' end diff --git a/opensearch-api/spec/opensearch/api/actions/mtermvectors_spec.rb b/opensearch-api/spec/opensearch/api/actions/mtermvectors_spec.rb index 77660a368..556facdc7 100644 --- a/opensearch-api/spec/opensearch/api/actions/mtermvectors_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/mtermvectors_spec.rb @@ -48,6 +48,7 @@ context 'when a list of ids is passed instead of a body' do let(:method) { 'GET' } + it 'performs the request' do expect(client_double.mtermvectors(index: 'my-index', ids: [1, 2, 3])).to eq({}) end diff --git a/opensearch-api/spec/opensearch/api/actions/nodes/hot_threads_spec.rb b/opensearch-api/spec/opensearch/api/actions/nodes/hot_threads_spec.rb index f0fc3f2b7..8d4b3eab1 100644 --- a/opensearch-api/spec/opensearch/api/actions/nodes/hot_threads_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/nodes/hot_threads_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.nodes#hot_threads' do - let(:expected_args) do [ - 'GET', - url, - {}, - nil, - {} + 'GET', + url, + {}, + nil, + {} ] end @@ -47,7 +46,6 @@ end context 'when the node id is specified' do - let(:url) do '_cluster/nodes/foo/hot_threads' end @@ -58,7 +56,6 @@ end context 'when the path must be URL-escaped' do - let(:url) do '_cluster/nodes/foo%5Ebar/hot_threads' end diff --git a/opensearch-api/spec/opensearch/api/actions/nodes/info_spec.rb b/opensearch-api/spec/opensearch/api/actions/nodes/info_spec.rb index 0f15c3d87..41482ccb9 100644 --- a/opensearch-api/spec/opensearch/api/actions/nodes/info_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/nodes/info_spec.rb @@ -27,31 +27,32 @@ require 'spec_helper' describe 'client.nodes#info' do - let(:expected_args) do [ - 'GET', - url, - params, - nil, - {} + 'GET', + url, + params, + nil, + {} ] end + let(:params) do + {} + end let(:url) do '_nodes' end - it 'performs the request' do - expect(client_double.nodes.info).to eq({}) - end - let(:params) do {} end - context 'when the node id is specified' do + it 'performs the request' do + expect(client_double.nodes.info).to eq({}) + end + context 'when the node id is specified' do let(:url) do '_nodes/foo' end @@ -62,18 +63,16 @@ end context 'when multiple node ids are specified as a list' do - let(:url) do '_nodes/A,B,C' end it 'performs the request' do - expect(client_double.nodes.info(node_id: ['A', 'B', 'C'])).to eq({}) + expect(client_double.nodes.info(node_id: %w[A B C])).to eq({}) end end context 'when multiple node ids are specified as a String' do - let(:url) do '_nodes/A,B,C' end @@ -84,7 +83,6 @@ end context 'when URL params are specified' do - let(:url) do '_nodes' end @@ -99,13 +97,12 @@ end context 'when metrics are specified' do - let(:url) do '_nodes/http,network' end it 'performs the request' do - expect(client_double.nodes.info(metric: ['http', 'network'])).to eq({}) + expect(client_double.nodes.info(metric: %w[http network])).to eq({}) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/nodes/reload_secure_settings_spec.rb b/opensearch-api/spec/opensearch/api/actions/nodes/reload_secure_settings_spec.rb index add03db23..0a6194c61 100644 --- a/opensearch-api/spec/opensearch/api/actions/nodes/reload_secure_settings_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/nodes/reload_secure_settings_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client#reload_secure_settings' do - let(:expected_args) do [ - 'POST', - url, - params, - body, - {} + 'POST', + url, + params, + body, + {} ] end @@ -43,11 +42,10 @@ let(:body) { nil } it 'performs the request' do - expect(client_double.nodes.reload_secure_settings()).to eq({}) + expect(client_double.nodes.reload_secure_settings).to eq({}) end context 'when a node id is specified' do - let(:url) do '_nodes/foo/reload_secure_settings' end @@ -58,7 +56,7 @@ end context 'when more than one node id is specified as a string' do - let(:body){ { foo: 'bar' } } + let(:body) { { foo: 'bar' } } let(:url) do '_nodes/foo,bar/reload_secure_settings' @@ -70,20 +68,19 @@ end context 'when more than one node id is specified as a list' do - let(:body){ { foo: 'bar' } } + let(:body) { { foo: 'bar' } } let(:url) do '_nodes/foo,bar/reload_secure_settings' end it 'performs the request' do - expect(client_double.nodes.reload_secure_settings(node_id: ['foo', 'bar'], body: { foo: 'bar' })).to eq({}) + expect(client_double.nodes.reload_secure_settings(node_id: %w[foo bar], body: { foo: 'bar' })).to eq({}) end end context 'when a timeout param is specified' do - let(:params) do - { timeout: '30s'} + { timeout: '30s' } end it 'performs the request' do diff --git a/opensearch-api/spec/opensearch/api/actions/nodes/shutdown_spec.rb b/opensearch-api/spec/opensearch/api/actions/nodes/shutdown_spec.rb index 40d823545..bdb738287 100644 --- a/opensearch-api/spec/opensearch/api/actions/nodes/shutdown_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/nodes/shutdown_spec.rb @@ -27,31 +27,32 @@ require 'spec_helper' describe 'client.nodes#shutdown' do - let(:expected_args) do [ - 'POST', - url, - params, - nil, - nil + 'POST', + url, + params, + nil, + nil ] end + let(:params) do + {} + end let(:url) do '_cluster/nodes/_shutdown' end - it 'performs the request' do - expect(client_double.nodes.shutdown).to eq({}) - end - let(:params) do {} end - context 'when the node id is specified' do + it 'performs the request' do + expect(client_double.nodes.shutdown).to eq({}) + end + context 'when the node id is specified' do let(:url) do '_cluster/nodes/foo/_shutdown' end @@ -62,18 +63,16 @@ end context 'when multiple node ids are specified as a list' do - let(:url) do '_cluster/nodes/A,B,C/_shutdown' end it 'performs the request' do - expect(client_double.nodes.shutdown(node_id: ['A', 'B', 'C'])).to eq({}) + expect(client_double.nodes.shutdown(node_id: %w[A B C])).to eq({}) end end context 'when multiple node ids are specified as a String' do - let(:url) do '_cluster/nodes/A,B,C/_shutdown' end diff --git a/opensearch-api/spec/opensearch/api/actions/nodes/stats_spec.rb b/opensearch-api/spec/opensearch/api/actions/nodes/stats_spec.rb index fceb37053..ed4efc982 100644 --- a/opensearch-api/spec/opensearch/api/actions/nodes/stats_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/nodes/stats_spec.rb @@ -27,31 +27,32 @@ require 'spec_helper' describe 'client.nodes#stats' do - let(:expected_args) do [ - 'GET', - url, - params, - nil, - {} + 'GET', + url, + params, + nil, + {} ] end + let(:params) do + {} + end let(:url) do '_nodes/stats' end - it 'performs the request' do - expect(client_double.nodes.stats).to eq({}) - end - let(:params) do {} end - context 'when the node id is specified' do + it 'performs the request' do + expect(client_double.nodes.stats).to eq({}) + end + context 'when the node id is specified' do let(:url) do '_nodes/foo/stats' end @@ -62,18 +63,16 @@ end context 'when metrics are specified' do - let(:url) do '_nodes/stats/http,fs' end it 'performs the request' do - expect(client_double.nodes.stats(metric: [:http, :fs])).to eq({}) + expect(client_double.nodes.stats(metric: %i[http fs])).to eq({}) end end context 'when index metric is specified' do - let(:url) do '_nodes/stats/indices/filter_cache' end diff --git a/opensearch-api/spec/opensearch/api/actions/ping_spec.rb b/opensearch-api/spec/opensearch/api/actions/ping_spec.rb index 990776852..e4ab0be40 100644 --- a/opensearch-api/spec/opensearch/api/actions/ping_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/ping_spec.rb @@ -27,34 +27,31 @@ require 'spec_helper' describe 'client#ping' do - let(:expected_args) do [ - 'HEAD', - '', - {}, - nil, - {} + 'HEAD', + '', + {}, + nil, + {} ] end it 'performs the request' do - expect(client_double.ping).to eq(true) + expect(client_double.ping).to be(true) end context 'when the response is a 404' do - let(:response_double) do double('response', status: 404, body: {}, headers: {}) end it 'returns false' do - expect(client_double.ping).to eq(false) + expect(client_double.ping).to be(false) end end context 'when a 404 \'not found\' exception is raised' do - before do allow(client).to receive(:perform_request).and_raise(StandardError.new('404 NotFound')) end @@ -64,12 +61,11 @@ end it 'returns false' do - expect(client.ping).to eq(false) + expect(client.ping).to be(false) end end context 'when \'connection failed\' exception is raised' do - before do allow(client).to receive(:perform_request).and_raise(StandardError.new('ConnectionFailed')) end @@ -79,7 +75,7 @@ end it 'returns false' do - expect(client.ping).to eq(false) + expect(client.ping).to be(false) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/reindex_spec.rb b/opensearch-api/spec/opensearch/api/actions/reindex_spec.rb index 238e08779..17b30bd41 100644 --- a/opensearch-api/spec/opensearch/api/actions/reindex_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/reindex_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client#reindex' do - let(:expected_args) do [ - 'POST', - '_reindex', - {}, - {}, - {} + 'POST', + '_reindex', + {}, + {}, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/remote/info_spec.rb b/opensearch-api/spec/opensearch/api/actions/remote/info_spec.rb index b2cae1a47..27f433fed 100644 --- a/opensearch-api/spec/opensearch/api/actions/remote/info_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/remote/info_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.remote#info' do - let(:expected_args) do [ - 'GET', - '_remote/info', - {}, - nil, - nil + 'GET', + '_remote/info', + {}, + nil, + nil ] end diff --git a/opensearch-api/spec/opensearch/api/actions/search_shards_spec.rb b/opensearch-api/spec/opensearch/api/actions/search_shards_spec.rb index 788d5d5ae..053ba41e6 100644 --- a/opensearch-api/spec/opensearch/api/actions/search_shards_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/search_shards_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client#search_shards' do - let(:expected_args) do [ - 'GET', - '_search_shards', - {}, - nil, - {} + 'GET', + '_search_shards', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/search_spec.rb b/opensearch-api/spec/opensearch/api/actions/search_spec.rb index b31ab1bd9..7c402543b 100644 --- a/opensearch-api/spec/opensearch/api/actions/search_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/search_spec.rb @@ -51,7 +51,7 @@ end it 'has a default value for index' do - expect(client_double.search()) + expect(client_double.search) end context 'when a request definition is specified' do @@ -70,7 +70,6 @@ end context 'when an index is specified' do - let(:url) do 'foo/_search' end @@ -81,7 +80,6 @@ end context 'when an index is specified' do - let(:url) do 'foo/_search' end @@ -92,18 +90,16 @@ end context 'when multiple indices are specified' do - let(:url) do 'foo,bar/_search' end it 'performs the request' do - expect(client_double.search(index: ['foo', 'bar'])) + expect(client_double.search(index: %w[foo bar])) end end context 'when there are URL params' do - let(:url) do '_search' end @@ -118,15 +114,14 @@ end context 'when there are invalid URL params' do - let(:client) do Class.new { include OpenSearch::API }.new end it 'raises an ArgumentError' do - expect{ + expect do client.search(search_type: 'count', qwertypoiuy: 'asdflkjhg') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/search_template_spec.rb b/opensearch-api/spec/opensearch/api/actions/search_template_spec.rb index 725326c35..c545ffdd9 100644 --- a/opensearch-api/spec/opensearch/api/actions/search_template_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/search_template_spec.rb @@ -31,7 +31,7 @@ [ 'POST', 'foo/_search/template', - { }, + {}, { foo: 'bar' }, {} ] diff --git a/opensearch-api/spec/opensearch/api/actions/shutdown/delete_node_spec.rb b/opensearch-api/spec/opensearch/api/actions/shutdown/delete_node_spec.rb index 598369c0d..2e1648f2f 100644 --- a/opensearch-api/spec/opensearch/api/actions/shutdown/delete_node_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/shutdown/delete_node_spec.rb @@ -36,18 +36,21 @@ {} ] end - - it 'performs the request' do - expect(client_double.shutdown.delete_node(node_id: 'id')).to eq({}) + let(:client) do + Class.new { include OpenSearch::API }.new end let(:client) do Class.new { include OpenSearch::API }.new end + it 'performs the request' do + expect(client_double.shutdown.delete_node(node_id: 'id')).to eq({}) + end + it 'raises an error if no node_id is provided' do - expect { + expect do client.shutdown.delete_node - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end diff --git a/opensearch-api/spec/opensearch/api/actions/shutdown/put_node_spec.rb b/opensearch-api/spec/opensearch/api/actions/shutdown/put_node_spec.rb index a95737039..dfc5f0c06 100644 --- a/opensearch-api/spec/opensearch/api/actions/shutdown/put_node_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/shutdown/put_node_spec.rb @@ -36,24 +36,27 @@ {} ] end - - it 'performs the request' do - expect(client_double.shutdown.put_node(body: {}, node_id: 'id')).to eq({}) + let(:client) do + Class.new { include OpenSearch::API }.new end let(:client) do Class.new { include OpenSearch::API }.new end + it 'performs the request' do + expect(client_double.shutdown.put_node(body: {}, node_id: 'id')).to eq({}) + end + it 'raises an error if no node_id is provided' do - expect { + expect do client.shutdown.put_node(body: {}) - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'raises an error if no body is provided' do - expect { + expect do client.shutdown.put_node(node_id: 'id') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end diff --git a/opensearch-api/spec/opensearch/api/actions/snapshot/clone_spec.rb b/opensearch-api/spec/opensearch/api/actions/snapshot/clone_spec.rb index 257b233b9..4ab043070 100644 --- a/opensearch-api/spec/opensearch/api/actions/snapshot/clone_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/snapshot/clone_spec.rb @@ -29,11 +29,11 @@ describe 'client.snapshot#clone' do let(:expected_args) do [ - 'PUT', - '_snapshot/foo/bar/_clone/snapshot', - {}, - {}, - {} + 'PUT', + '_snapshot/foo/bar/_clone/snapshot', + {}, + {}, + {} ] end @@ -42,27 +42,27 @@ end it 'requires the :body argument' do - expect { + expect do client.snapshot.clone(snapshot: 'bar') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'requires the :repository argument' do - expect { + expect do client.snapshot.clone(snapshot: 'foo', body: {}) - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'requires the :snapshot argument' do - expect { + expect do client.snapshot.clone(repository: 'foo', body: {}) - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'requires the :target_snapshot argument' do - expect { + expect do client.snapshot.clone(repository: 'foo', body: {}, snapshot: 'bar') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request' do diff --git a/opensearch-api/spec/opensearch/api/actions/snapshot/create_repository_spec.rb b/opensearch-api/spec/opensearch/api/actions/snapshot/create_repository_spec.rb index f39f225f9..09faa0a6a 100644 --- a/opensearch-api/spec/opensearch/api/actions/snapshot/create_repository_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/snapshot/create_repository_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.snapshot#create_repository' do - let(:expected_args) do [ - 'PUT', - '_snapshot/foo', - {}, - {}, - {} + 'PUT', + '_snapshot/foo', + {}, + {}, + {} ] end @@ -43,15 +42,15 @@ end it 'requires the :body argument' do - expect { + expect do client.snapshot.create_repository(repository: 'foo') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'requires the :repository argument' do - expect { + expect do client.snapshot.create_repository(body: {}) - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request' do diff --git a/opensearch-api/spec/opensearch/api/actions/snapshot/create_spec.rb b/opensearch-api/spec/opensearch/api/actions/snapshot/create_spec.rb index b736d05b2..1f6d9ed23 100644 --- a/opensearch-api/spec/opensearch/api/actions/snapshot/create_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/snapshot/create_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.snapshot#create' do - let(:expected_args) do [ - 'PUT', - '_snapshot/foo/bar', - {}, - {}, - {} + 'PUT', + '_snapshot/foo/bar', + {}, + {}, + {} ] end @@ -43,15 +42,15 @@ end it 'requires the :repository argument' do - expect { + expect do client.snapshot.create(snapshot: 'bar', body: {}) - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'requires the :snapshot argument' do - expect { + expect do client.snapshot.create(repository: 'foo', body: {}) - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request' do diff --git a/opensearch-api/spec/opensearch/api/actions/snapshot/delete_repository_spec.rb b/opensearch-api/spec/opensearch/api/actions/snapshot/delete_repository_spec.rb index f196a6287..24da1354c 100644 --- a/opensearch-api/spec/opensearch/api/actions/snapshot/delete_repository_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/snapshot/delete_repository_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.snapshot#delete_repository' do - let(:expected_args) do [ - 'DELETE', - url, - {}, - nil, - {} + 'DELETE', + url, + {}, + nil, + {} ] end @@ -47,13 +46,12 @@ end context 'when multiple indices are specified' do - let(:url) do '_snapshot/foo,bar' end it 'performs the request' do - expect(client_double.snapshot.delete_repository(repository: ['foo','bar'])).to eq({}) + expect(client_double.snapshot.delete_repository(repository: %w[foo bar])).to eq({}) end end end diff --git a/opensearch-api/spec/opensearch/api/actions/snapshot/delete_spec.rb b/opensearch-api/spec/opensearch/api/actions/snapshot/delete_spec.rb index 45a314c0d..6fded483f 100644 --- a/opensearch-api/spec/opensearch/api/actions/snapshot/delete_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/snapshot/delete_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.snapshot#delete' do - let(:expected_args) do [ - 'DELETE', - '_snapshot/foo/bar', - {}, - nil, - {} + 'DELETE', + '_snapshot/foo/bar', + {}, + nil, + {} ] end @@ -43,15 +42,15 @@ end it 'requires the :snapshot argument' do - expect { + expect do client.snapshot.delete(repository: 'foo') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'requires the :repository argument' do - expect { + expect do client.snapshot.delete(snapshot: 'bar') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request' do diff --git a/opensearch-api/spec/opensearch/api/actions/snapshot/get_repository_spec.rb b/opensearch-api/spec/opensearch/api/actions/snapshot/get_repository_spec.rb index 96c70811a..df033b773 100644 --- a/opensearch-api/spec/opensearch/api/actions/snapshot/get_repository_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/snapshot/get_repository_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.snapshot#get_repository' do - let(:expected_args) do [ - 'GET', - '_snapshot/foo', - {}, - nil, - {} + 'GET', + '_snapshot/foo', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/snapshot/get_spec.rb b/opensearch-api/spec/opensearch/api/actions/snapshot/get_spec.rb index 9680c71e2..2c7505549 100644 --- a/opensearch-api/spec/opensearch/api/actions/snapshot/get_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/snapshot/get_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.snapshot#get' do - let(:expected_args) do [ - 'GET', - '_snapshot/foo/bar', - {}, - nil, - {} + 'GET', + '_snapshot/foo/bar', + {}, + nil, + {} ] end @@ -43,15 +42,15 @@ end it 'requires the :snapshot argument' do - expect { + expect do client.snapshot.get(repository: 'foo') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'requires the :repository argument' do - expect { + expect do client.snapshot.get(snapshot: 'bar') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request' do diff --git a/opensearch-api/spec/opensearch/api/actions/snapshot/repository_analize_spec.rb b/opensearch-api/spec/opensearch/api/actions/snapshot/repository_analize_spec.rb index e7925aa1b..76ea76705 100644 --- a/opensearch-api/spec/opensearch/api/actions/snapshot/repository_analize_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/snapshot/repository_analize_spec.rb @@ -36,22 +36,25 @@ {} ] end + let(:client) do + Class.new { include OpenSearch::API }.new + end let(:url) do '_snapshot/foo/_analyze' end - it 'performs the request' do - expect(client_double.snapshot.repository_analyze(repository: 'foo')).to eq({}) - end - let(:client) do Class.new { include OpenSearch::API }.new end + it 'performs the request' do + expect(client_double.snapshot.repository_analyze(repository: 'foo')).to eq({}) + end + it 'requires the :repository argument' do - expect { + expect do client.snapshot.repository_analyze - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end diff --git a/opensearch-api/spec/opensearch/api/actions/snapshot/restore_spec.rb b/opensearch-api/spec/opensearch/api/actions/snapshot/restore_spec.rb index 374a62b88..67a8efbcf 100644 --- a/opensearch-api/spec/opensearch/api/actions/snapshot/restore_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/snapshot/restore_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.snapshot#restore' do - let(:expected_args) do [ - 'POST', - '_snapshot/foo/bar/_restore', - {}, - nil, - {} + 'POST', + '_snapshot/foo/bar/_restore', + {}, + nil, + {} ] end @@ -43,15 +42,15 @@ end it 'requires the :snapshot argument' do - expect { + expect do client.snapshot.restore(repository: 'foo') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'requires the :repository argument' do - expect { + expect do client.snapshot.restore(snapshot: 'bar') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request' do diff --git a/opensearch-api/spec/opensearch/api/actions/snapshot/status_spec.rb b/opensearch-api/spec/opensearch/api/actions/snapshot/status_spec.rb index d0a5e8c59..5c2174be1 100644 --- a/opensearch-api/spec/opensearch/api/actions/snapshot/status_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/snapshot/status_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.snapshot#status' do - let(:expected_args) do [ - 'GET', - url, - {}, - nil, - {} + 'GET', + url, + {}, + nil, + {} ] end @@ -47,7 +46,6 @@ end context 'when a repository and snapshot are specified' do - let(:url) do '_snapshot/foo/bar/_status' end diff --git a/opensearch-api/spec/opensearch/api/actions/snapshot/verify_repository_spec.rb b/opensearch-api/spec/opensearch/api/actions/snapshot/verify_repository_spec.rb index 36b765190..debd501e7 100644 --- a/opensearch-api/spec/opensearch/api/actions/snapshot/verify_repository_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/snapshot/verify_repository_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.snapshot#verify_repository' do - let(:expected_args) do [ - 'POST', - '_snapshot/foo/_verify', - {}, - nil, - {} + 'POST', + '_snapshot/foo/_verify', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/tasks/cancel_spec.rb b/opensearch-api/spec/opensearch/api/actions/tasks/cancel_spec.rb index 5deb647f3..9012a784a 100644 --- a/opensearch-api/spec/opensearch/api/actions/tasks/cancel_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/tasks/cancel_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.tasks#cancel' do - let(:expected_args) do [ - 'POST', - url, - {}, - nil, - {} + 'POST', + url, + {}, + nil, + {} ] end @@ -47,7 +46,6 @@ end context 'when a task id is specified' do - let(:url) do '_tasks/foo/_cancel' end diff --git a/opensearch-api/spec/opensearch/api/actions/tasks/get_spec.rb b/opensearch-api/spec/opensearch/api/actions/tasks/get_spec.rb index 88fd6551a..cb3e65d4a 100644 --- a/opensearch-api/spec/opensearch/api/actions/tasks/get_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/tasks/get_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.tasks#get' do - let(:expected_args) do [ - 'GET', - '_tasks/foo1', - {}, - nil, - {} + 'GET', + '_tasks/foo1', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/tasks/list_spec.rb b/opensearch-api/spec/opensearch/api/actions/tasks/list_spec.rb index 57ba330c1..3efa80e0e 100644 --- a/opensearch-api/spec/opensearch/api/actions/tasks/list_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/tasks/list_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client.tasks#list' do - let(:expected_args) do [ - 'GET', - url, - {}, - nil, - {} + 'GET', + url, + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/termvectors_spec.rb b/opensearch-api/spec/opensearch/api/actions/termvectors_spec.rb index 90a830e30..cd6271cef 100644 --- a/opensearch-api/spec/opensearch/api/actions/termvectors_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/termvectors_spec.rb @@ -54,9 +54,9 @@ end it 'requires the :index argument' do - expect { + expect do client.termvectors(id: '1') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request' do diff --git a/opensearch-api/spec/opensearch/api/actions/update_by_query_spec.rb b/opensearch-api/spec/opensearch/api/actions/update_by_query_spec.rb index 98cacd30d..857a3baf8 100644 --- a/opensearch-api/spec/opensearch/api/actions/update_by_query_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/update_by_query_spec.rb @@ -27,14 +27,13 @@ require 'spec_helper' describe 'client#update_by_query' do - let(:expected_args) do [ - 'POST', - 'foo/_update_by_query', - {}, - nil, - {} + 'POST', + 'foo/_update_by_query', + {}, + nil, + {} ] end diff --git a/opensearch-api/spec/opensearch/api/actions/update_document_spec.rb b/opensearch-api/spec/opensearch/api/actions/update_document_spec.rb index 8e142ebc7..778fa14a2 100644 --- a/opensearch-api/spec/opensearch/api/actions/update_document_spec.rb +++ b/opensearch-api/spec/opensearch/api/actions/update_document_spec.rb @@ -27,19 +27,18 @@ require 'spec_helper' describe 'client#update' do - let(:expected_args) do [ - 'POST', - url, - params, - body, - {} + 'POST', + url, + params, + body, + {} ] end let(:body) do - { doc: { } } + { doc: {} } end let(:url) do @@ -55,15 +54,15 @@ end it 'requires the :index argument' do - expect { + expect do client.update(id: '1') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'requires the :id argument' do - expect { + expect do client.update(index: 'foo') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end it 'performs the request' do @@ -71,7 +70,6 @@ end context 'when URL parameters are provided' do - let(:url) do 'foo/_update/1' end @@ -86,16 +84,14 @@ end context 'when invalid parameters are specified' do - it 'raises an ArgumentError' do - expect { + expect do client.update(index: 'foo', id: '1', body: { doc: {} }, qwertypoiuy: 'asdflkjhg') - }.to raise_exception(ArgumentError) + end.to raise_exception(ArgumentError) end end context 'when the request needs to be URL-escaped' do - let(:url) do 'foo%5Ebar/_update/1' end @@ -110,21 +106,19 @@ end context 'when a NotFound exception is raised' do - before do allow(client).to receive(:perform_request).and_raise(NotFound) end it 'raises it to the user' do - expect { + expect do client.update(index: 'foo', id: 'XXX', body: {}) - }.to raise_exception(NotFound) + end.to raise_exception(NotFound) end context 'when the :ignore parameter is specified' do - it 'does not raise the error to the user' do - expect(client.update(index: 'foo', id: 'XXX', body: {}, ignore: 404)).to eq(false) + expect(client.update(index: 'foo', id: 'XXX', body: {}, ignore: 404)).to be(false) end end end diff --git a/opensearch-api/spec/opensearch/api/api_spec.rb b/opensearch-api/spec/opensearch/api/api_spec.rb index 874c05405..8d0e9ee94 100644 --- a/opensearch-api/spec/opensearch/api/api_spec.rb +++ b/opensearch-api/spec/opensearch/api/api_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::API do - describe '#settings' do - it 'allows access to settings' do expect(described_class.settings).not_to be_nil end @@ -39,7 +37,6 @@ end context 'when settings are changed' do - before do OpenSearch::API.settings[:foo] = 'bar' end diff --git a/opensearch-api/spec/opensearch/api/client_spec.rb b/opensearch-api/spec/opensearch/api/client_spec.rb index cdea4defa..cd45d5970 100644 --- a/opensearch-api/spec/opensearch/api/client_spec.rb +++ b/opensearch-api/spec/opensearch/api/client_spec.rb @@ -27,27 +27,23 @@ require 'spec_helper' describe 'API Client' do - let(:client) do Class.new { include OpenSearch::API }.new end describe '#cluster' do - it 'responds to the method' do expect(client.respond_to?(:cluster)).to be(true) end end describe '#indices' do - it 'responds to the method' do expect(client.respond_to?(:indices)).to be(true) end end describe '#bulk' do - it 'responds to the method' do expect(client.respond_to?(:bulk)).to be(true) end diff --git a/opensearch-api/spec/opensearch/api/rest_api_yaml_spec.rb b/opensearch-api/spec/opensearch/api/rest_api_yaml_spec.rb index cd32c556b..441b97724 100644 --- a/opensearch-api/spec/opensearch/api/rest_api_yaml_spec.rb +++ b/opensearch-api/spec/opensearch/api/rest_api_yaml_spec.rb @@ -47,9 +47,9 @@ next end - context "#{file.gsub("#{YAML_FILES_DIRECTORY}/", '')}" do + context file.gsub("#{YAML_FILES_DIRECTORY}/", '').to_s do test_file.tests.each do |test| - context "#{test.description}" do + context test.description.to_s do if test.skip_test?(ADMIN_CLIENT) skip 'Test contains feature(s) not yet supported or version is not satisfied' else diff --git a/opensearch-api/spec/opensearch/api/utils_spec.rb b/opensearch-api/spec/opensearch/api/utils_spec.rb index b9e91f708..3c7e14ac7 100644 --- a/opensearch-api/spec/opensearch/api/utils_spec.rb +++ b/opensearch-api/spec/opensearch/api/utils_spec.rb @@ -27,13 +27,11 @@ require 'spec_helper' describe OpenSearch::API::Utils do - let(:utils) do Class.new { include OpenSearch::API::Utils }.new end describe '#__escape' do - it 'encodes Unicode characters' do expect(utils.__escape('中文')).to eq('%E4%B8%AD%E6%96%87') end @@ -55,13 +53,12 @@ end describe '#__listify' do - it 'creates a list from a single value' do expect(utils.__listify('foo')).to eq('foo') end it 'creates a list from an array' do - expect(utils.__listify(['foo', 'bar'])).to eq('foo,bar') + expect(utils.__listify(%w[foo bar])).to eq('foo,bar') end it 'creates a list from multiple arguments' do @@ -77,21 +74,19 @@ end context 'when the escape option is set to false' do - it 'does not escape the characters' do - expect(utils.__listify(['foo', 'bar^bam'], :escape => false)).to eq('foo,bar^bam') + expect(utils.__listify(['foo', 'bar^bam'], escape: false)).to eq('foo,bar^bam') end end end describe '#__pathify' do - it 'creates a path from a single value' do expect(utils.__pathify('foo')).to eq('foo') end it 'creates a path from an array' do - expect(utils.__pathify(['foo', 'bar'])).to eq('foo/bar') + expect(utils.__pathify(%w[foo bar])).to eq('foo/bar') end it 'ignores nil values' do @@ -104,14 +99,12 @@ end describe '#__bulkify' do - context 'when the input is an array of hashes' do - let(:result) do utils.__bulkify [ - { :index => { :_index => 'myindexA', :_id => '1', :data => { :title => 'Test' } } }, - { :update => { :_index => 'myindexB', :_id => '2', :data => { :doc => { :title => 'Update' } } } }, - { :delete => { :_index => 'myindexC', :_id => '3' } } + { index: { _index: 'myindexA', _id: '1', data: { title: 'Test' } } }, + { update: { _index: 'myindexB', _id: '2', data: { doc: { title: 'Update' } } } }, + { delete: { _index: 'myindexC', _id: '3' } } ] end @@ -131,9 +124,8 @@ end context 'when the input is an array of strings' do - let(:result) do - utils.__bulkify(['{"foo":"bar"}','{"moo":"bam"}']) + utils.__bulkify(['{"foo":"bar"}', '{"moo":"bam"}']) end let(:expected_string) do @@ -149,9 +141,8 @@ end context 'when the input is an array of header/data pairs' do - let(:result) do - utils.__bulkify([{ foo: 'bar' }, { moo: 'bam' },{ foo: 'baz' }]) + utils.__bulkify([{ foo: 'bar' }, { moo: 'bam' }, { foo: 'baz' }]) end let(:expected_string) do @@ -168,7 +159,6 @@ end context 'when the payload has the :data option' do - let(:input) do { index: { foo: 'bar', data: { moo: 'bam' } } } end @@ -194,13 +184,12 @@ end context 'when the payload has nested :data options' do - let(:data) do { data: { a: 'b', data: { c: 'd' } } } end let(:result) do - utils.__bulkify([{ index: { foo: 'bar'} } , data]) + utils.__bulkify([{ index: { foo: 'bar' } }, data]) end let(:lines) do @@ -227,50 +216,44 @@ end end - context '#__validate_and_extract_params' do - + describe '#__validate_and_extract_params' do it 'listify Arrays' do - expect(utils.__validate_and_extract_params({ foo: ['a', 'b'] }, [:foo] )).to eq(foo: 'a,b') + expect(utils.__validate_and_extract_params({ foo: %w[a b] }, [:foo])).to eq(foo: 'a,b') end it 'does not escape the parameters' do - expect(utils.__validate_and_extract_params({ foo: ['a.*', 'b.*'] }, [:foo] )).to eq(foo: 'a.*,b.*') + expect(utils.__validate_and_extract_params({ foo: ['a.*', 'b.*'] }, [:foo])).to eq(foo: 'a.*,b.*') end context 'when the params are valid' do - it 'extracts the valid params from the hash' do - expect(utils.__validate_and_extract_params({ foo: 'qux' }, [:foo, :bar]) ).to eq(foo: 'qux') + expect(utils.__validate_and_extract_params({ foo: 'qux' }, %i[foo bar])).to eq(foo: 'qux') end end context 'when the params are invalid' do - it 'raises an ArgumentError' do - expect { - utils.__validate_and_extract_params({ foo: 'qux', bam: 'mux' }, [:foo, :bar]) - }.to raise_exception(ArgumentError) + expect do + utils.__validate_and_extract_params({ foo: 'qux', bam: 'mux' }, %i[foo bar]) + end.to raise_exception(ArgumentError) end end context 'when COMMON_PARAMS are provided' do - it 'extracts the params' do - expect(utils.__validate_and_extract_params({ index: 'foo'}, [:foo])).to eq({}) + expect(utils.__validate_and_extract_params({ index: 'foo' }, [:foo])).to eq({}) end end context 'when COMMON_QUERY_PARAMS are provided' do - it 'extracts the params' do expect(utils.__validate_and_extract_params(format: 'yaml')).to eq(format: 'yaml') end end context 'when the :skip_paramter_validation option is set' do - let(:result) do - utils.__validate_and_extract_params( { foo: 'q', bam: 'm' }, [:foo, :bar], { skip_parameter_validation: true } ) + utils.__validate_and_extract_params({ foo: 'q', bam: 'm' }, %i[foo bar], { skip_parameter_validation: true }) end it 'skips parameter validation' do @@ -279,7 +262,6 @@ end context 'when the module has the setting to skip parameter validation' do - around do |example| original_value = OpenSearch::API.settings[:skip_parameter_validation] OpenSearch::API.settings[:skip_parameter_validation] = true @@ -288,7 +270,7 @@ end let(:result) do - utils.__validate_and_extract_params( { foo: 'q', bam: 'm' }, [:foo, :bar]) + utils.__validate_and_extract_params({ foo: 'q', bam: 'm' }, %i[foo bar]) end it 'applies the module setting' do @@ -298,44 +280,40 @@ end describe '#__extract_parts' do - it 'extracts parts with true value from a Hash' do - expect(utils.__extract_parts({ foo: true, moo: 'blah' }, [:foo, :bar])).to eq(['foo']) + expect(utils.__extract_parts({ foo: true, moo: 'blah' }, %i[foo bar])).to eq(['foo']) end it 'extracts parts with string value from a Hash' do - expect(utils.__extract_parts({ foo: 'qux', moo: 'blah' }, [:foo, :bar])).to eq(['qux']) + expect(utils.__extract_parts({ foo: 'qux', moo: 'blah' }, %i[foo bar])).to eq(['qux']) end end - context '#__rescue_from_not_found' do - + describe '#__rescue_from_not_found' do it 'returns false if exception class name contains \'NotFound\'' do expect(utils.__rescue_from_not_found { raise NotFound }).to be(false) end it 'returns false if exception message contains \'Not Found\'' do - expect(utils.__rescue_from_not_found { raise StandardError.new "Not Found" }).to be(false) - expect(utils.__rescue_from_not_found { raise StandardError.new "NotFound" }).to be(false) + expect(utils.__rescue_from_not_found { raise StandardError, 'Not Found' }).to be(false) + expect(utils.__rescue_from_not_found { raise StandardError, 'NotFound' }).to be(false) end it 'raises the exception if the class name and message do not include \'NotFound\'' do - expect { - utils.__rescue_from_not_found { raise StandardError.new "Any other exception" } - }.to raise_exception(StandardError) + expect do + utils.__rescue_from_not_found { raise StandardError, 'Any other exception' } + end.to raise_exception(StandardError) end end - context '#__report_unsupported_parameters' do - + describe '#__report_unsupported_parameters' do context 'when the parameters are passed as Symbols' do - let(:arguments) do { foo: 'bar', moo: 'bam', baz: 'qux' } end let(:unsupported_params) do - [ :foo, :moo] + %i[foo moo] end let(:message) do @@ -346,19 +324,18 @@ end it 'prints the unsupported parameters' do - expect(message).to match(/You are using unsupported parameter \[\:foo\]/) - expect(message).to match(/You are using unsupported parameter \[\:moo\]/) + expect(message).to match(/You are using unsupported parameter \[:foo\]/) + expect(message).to match(/You are using unsupported parameter \[:moo\]/) end end context 'when the parameters are passed as Hashes' do - let(:arguments) do { foo: 'bar', moo: 'bam', baz: 'qux' } end let(:unsupported_params) do - [ :foo, :moo] + %i[foo moo] end let(:message) do @@ -369,22 +346,20 @@ end it 'prints the unsupported parameters' do - expect(message).to match(/You are using unsupported parameter \[\:foo\]/) - expect(message).to match(/You are using unsupported parameter \[\:moo\]/) + expect(message).to match(/You are using unsupported parameter \[:foo\]/) + expect(message).to match(/You are using unsupported parameter \[:moo\]/) end end context 'when the parameters are passed as a mix of Hashes and Symbols' do - let(:arguments) do { foo: 'bar', moo: 'bam', baz: 'qux' } end let(:unsupported_params) do - [ { :foo => { :explanation => 'NOT_SUPPORTED'} }, :moo ] + [{ foo: { explanation: 'NOT_SUPPORTED' } }, :moo] end - let(:message) do message = '' expect(Kernel).to receive(:warn) { |msg| message = msg } @@ -393,20 +368,19 @@ end it 'prints the unsupported parameters' do - expect(message).to match(/You are using unsupported parameter \[\:foo\]/) - expect(message).to match(/You are using unsupported parameter \[\:moo\]/) + expect(message).to match(/You are using unsupported parameter \[:foo\]/) + expect(message).to match(/You are using unsupported parameter \[:moo\]/) expect(message).to match(/NOT_SUPPORTED/) end end context 'when unsupported parameters are unused' do - let(:arguments) do { moo: 'bam', baz: 'qux' } end let(:unsupported_params) do - [ :foo ] + [:foo] end it 'prints the unsupported parameters' do @@ -417,7 +391,6 @@ end describe '#__report_unsupported_method' do - let(:message) do message = '' expect(Kernel).to receive(:warn) { |msg| message = msg } diff --git a/opensearch-api/spec/rest_yaml_tests_helper.rb b/opensearch-api/spec/rest_yaml_tests_helper.rb index af608609e..328970928 100644 --- a/opensearch-api/spec/rest_yaml_tests_helper.rb +++ b/opensearch-api/spec/rest_yaml_tests_helper.rb @@ -33,13 +33,14 @@ if (hosts = OPENSEARCH_URL) split_hosts = hosts.split(',').map do |host| - /(http\:\/\/)?\S+/.match(host) + %r{(http://)?\S+}.match(host) end uri = URI.parse(split_hosts.first[0]) TEST_HOST = uri.host TEST_PORT = uri.port else - TEST_HOST, TEST_PORT = 'localhost', '9200' + TEST_HOST = 'localhost' + TEST_PORT = '9200' end if defined?(TEST_HOST) && defined?(TEST_PORT) @@ -47,19 +48,19 @@ ADMIN_CLIENT = OpenSearch::Client.new(host: URL, transport_options: TRANSPORT_OPTIONS) - if ENV['QUIET'] == 'true' - DEFAULT_CLIENT = OpenSearch::Client.new(host: URL, transport_options: TRANSPORT_OPTIONS) - else - DEFAULT_CLIENT = OpenSearch::Client.new(host: URL, - transport_options: TRANSPORT_OPTIONS, - tracer: Logger.new($stdout)) - end + DEFAULT_CLIENT = if ENV.fetch('QUIET', nil) == 'true' + OpenSearch::Client.new(host: URL, transport_options: TRANSPORT_OPTIONS) + else + OpenSearch::Client.new(host: URL, + transport_options: TRANSPORT_OPTIONS, + tracer: Logger.new($stdout)) + end end YAML_FILES_DIRECTORY = "#{PROJECT_PATH}/../tmp/rest-api-spec/test/free" -SINGLE_TEST = if ENV['SINGLE_TEST'] && !ENV['SINGLE_TEST'].empty? - test_target = ENV['SINGLE_TEST'] +SINGLE_TEST = if ENV.fetch('SINGLE_TEST', nil) && !ENV['SINGLE_TEST'].empty? + test_target = ENV.fetch('SINGLE_TEST', nil) if test_target.match?(/\.yml$/) ["#{PROJECT_PATH}/../tmp/rest-api-spec/test/free/#{test_target}"] @@ -86,4 +87,4 @@ end # The features to skip -REST_API_YAML_SKIP_FEATURES = ['warnings', 'node_selector'].freeze +REST_API_YAML_SKIP_FEATURES = %w[warnings node_selector].freeze diff --git a/opensearch-api/spec/spec_helper.rb b/opensearch-api/spec/spec_helper.rb index ef0ab0ace..a4cbe64d5 100644 --- a/opensearch-api/spec/spec_helper.rb +++ b/opensearch-api/spec/spec_helper.rb @@ -24,7 +24,7 @@ # specific language governing permissions and limitations # under the License. -if ENV['COVERAGE'] && ENV['CI'].nil? +if ENV.fetch('COVERAGE', nil) && ENV['CI'].nil? require 'simplecov' SimpleCov.start { add_filter %r{^/test|spec/} } end @@ -43,16 +43,16 @@ require 'yaml' tracer = ::Logger.new(STDERR) -tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" } +tracer.formatter = ->(_s, _d, _p, m) { "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" } unless defined?(OPENSEARCH_URL) - OPENSEARCH_URL = ENV['OPENSEARCH_URL'] || - ENV['TEST_OPENSEARCH_SERVER'] || - "http://localhost:#{(ENV['TEST_CLUSTER_PORT'] || 9200)}" + OPENSEARCH_URL = ENV.fetch('OPENSEARCH_URL', nil) || + ENV.fetch('TEST_OPENSEARCH_SERVER', nil) || + "http://localhost:#{ENV.fetch('TEST_CLUSTER_PORT', nil) || 9200}" end DEFAULT_CLIENT = OpenSearch::Client.new(host: OPENSEARCH_URL, - tracer: (tracer unless ENV['QUIET'])) + tracer: (tracer unless ENV['QUIET'])) module HelperModule def self.included(context) diff --git a/opensearch-aws-sigv4/Gemfile b/opensearch-aws-sigv4/Gemfile index e45631a8e..41407adee 100644 --- a/opensearch-aws-sigv4/Gemfile +++ b/opensearch-aws-sigv4/Gemfile @@ -12,14 +12,14 @@ source 'https://rubygems.org' # Specify your gem's dependencies in opensearch-aws-sigv4.gemspec gemspec -if File.exist? File.expand_path("../../opensearch-api/opensearch-api.gemspec", __FILE__) - gem 'opensearch-api', :path => File.expand_path("../../opensearch-api", __FILE__), :require => false +if File.exist? File.expand_path('../opensearch-api/opensearch-api.gemspec', __dir__) + gem 'opensearch-api', path: File.expand_path('../opensearch-api', __dir__), require: false end -if File.exist? File.expand_path("../../opensearch-transport/opensearch-transport.gemspec", __FILE__) - gem 'opensearch-transport', :path => File.expand_path("../../opensearch-transport", __FILE__), :require => false +if File.exist? File.expand_path('../opensearch-transport/opensearch-transport.gemspec', __dir__) + gem 'opensearch-transport', path: File.expand_path('../opensearch-transport', __dir__), require: false end -if File.exist? File.expand_path("../../opensearch-ruby/opensearch-ruby.gemspec", __FILE__) - gem 'opensearch-ruby', :path => File.expand_path("../../opensearch-ruby", __FILE__), :require => false +if File.exist? File.expand_path('../opensearch-ruby/opensearch-ruby.gemspec', __dir__) + gem 'opensearch-ruby', path: File.expand_path('../opensearch-ruby', __dir__), require: false end diff --git a/opensearch-aws-sigv4/Rakefile b/opensearch-aws-sigv4/Rakefile index 6a739344b..ba32e0148 100644 --- a/opensearch-aws-sigv4/Rakefile +++ b/opensearch-aws-sigv4/Rakefile @@ -37,5 +37,5 @@ end require 'yard' YARD::Rake::YardocTask.new(:doc) do |t| - t.options = %w| --embed-mixins --markup=markdown | + t.options = %w[--embed-mixins --markup=markdown] end diff --git a/opensearch-aws-sigv4/bin/opensearch_sigv4_console b/opensearch-aws-sigv4/bin/opensearch_sigv4_console index 526c71cb9..cb9db5649 100755 --- a/opensearch-aws-sigv4/bin/opensearch_sigv4_console +++ b/opensearch-aws-sigv4/bin/opensearch_sigv4_console @@ -9,11 +9,9 @@ $LOAD_PATH.unshift(File.expand_path('../../opensearch-api/lib', __dir__)) require 'opensearch-aws-sigv4' gems_not_loaded = ['opensearch-dsl'].reject do |gem| - begin - (require gem) || true - rescue LoadError - false - end + (require gem) || true +rescue LoadError + false end unless gems_not_loaded.empty? diff --git a/opensearch-aws-sigv4/lib/opensearch-aws-sigv4.rb b/opensearch-aws-sigv4/lib/opensearch-aws-sigv4.rb index 5a939b7b1..c3c66db8b 100644 --- a/opensearch-aws-sigv4/lib/opensearch-aws-sigv4.rb +++ b/opensearch-aws-sigv4/lib/opensearch-aws-sigv4.rb @@ -59,7 +59,8 @@ def perform_request(method, path, params = {}, body = nil, headers = nil) http_method: method, url: signature_url(path, params), headers: headers, - body: signature_body) + body: signature_body + ) headers = (headers || {}).merge(signature.headers) log_signature_info(signature) @@ -75,7 +76,7 @@ def verify_open_search def signature_url(path, params) host = @transport.transport.hosts.dig(0, :host) path = '/' + path unless path.start_with?('/') - query_string = params.empty? ? '' : "#{Faraday::Utils::ParamsHash[params].to_query}" + query_string = params.empty? ? '' : Faraday::Utils::ParamsHash[params].to_query.to_s URI::HTTP.build(host: host, path: path, query: query_string) end @@ -99,7 +100,8 @@ def logger @logger = Logger.new( STDOUT, progname: 'Sigv4', - formatter: proc { |_severity, datetime, progname, msg| "\e[34m(#{datetime}) #{progname} - #{msg}\e[0m\n\n" }) + formatter: proc { |_severity, datetime, progname, msg| "\e[34m(#{datetime}) #{progname} - #{msg}\e[0m\n\n" } + ) end end end diff --git a/opensearch-aws-sigv4/opensearch-aws-sigv4.gemspec b/opensearch-aws-sigv4/opensearch-aws-sigv4.gemspec index 20ec17ad2..e157adf38 100644 --- a/opensearch-aws-sigv4/opensearch-aws-sigv4.gemspec +++ b/opensearch-aws-sigv4/opensearch-aws-sigv4.gemspec @@ -7,11 +7,11 @@ # Modifications Copyright OpenSearch Contributors. See # GitHub history for details. -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'opensearch-aws-sigv4/version' -signing_key_path = File.expand_path("../gem-private_key.pem") +signing_key_path = File.expand_path('../gem-private_key.pem') Gem::Specification.new do |s| s.name = 'opensearch-aws-sigv4' @@ -24,14 +24,15 @@ Gem::Specification.new do |s| s.metadata = { 'homepage_uri' => 'https://opensearch.org/docs/latest/', 'source_code_uri' => 'https://github.com/opensearch-project/opensearch-ruby/tree/main', - 'bug_tracker_uri' => 'https://github.com/opensearch-project/opensearch-ruby/issues' + 'bug_tracker_uri' => 'https://github.com/opensearch-project/opensearch-ruby/issues', + 'rubygems_mfa_required' => 'true' } s.files = `git ls-files`.split($/) s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) } - s.executables << 'opensearch_sigv4_console' - s.test_files = s.files.grep(%r{^(test|spec|features)/}) + s.executables << 'opensearch_sigv4_console' + s.test_files = s.files.grep(%r{^(test|spec|features)/}) - if $PROGRAM_NAME.end_with?("gem") && ARGV == ["build", __FILE__] && File.exist?(signing_key_path) + if $PROGRAM_NAME.end_with?('gem') && ARGV == ['build', __FILE__] && File.exist?(signing_key_path) s.signing_key = signing_key_path s.cert_chain = ['../certs/opensearch-rubygems.pem'] end @@ -39,12 +40,12 @@ Gem::Specification.new do |s| s.require_paths = ['lib'] s.bindir = 'bin' - s.extra_rdoc_files = [ 'README.md', 'LICENSE' ] - s.rdoc_options = [ '--charset=UTF-8' ] + s.extra_rdoc_files = ['README.md', 'LICENSE'] + s.rdoc_options = ['--charset=UTF-8'] s.required_ruby_version = '>= 2.5' - s.add_dependency 'aws-sigv4', '~> 1' + s.add_dependency 'aws-sigv4', '~> 1' s.add_dependency 'opensearch-ruby', '>= 1.0.1' s.add_development_dependency 'bundler' @@ -55,8 +56,8 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec' s.add_development_dependency 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius) s.add_development_dependency 'simplecov' - s.add_development_dependency 'yard' s.add_development_dependency 'timecop' + s.add_development_dependency 'yard' s.description = <<-DESC.gsub(/^ /, '') Ruby AWS Sigv4 Client for OpenSearch diff --git a/opensearch-aws-sigv4/spec/spec_helper.rb b/opensearch-aws-sigv4/spec/spec_helper.rb index 10814b175..80fa4374a 100644 --- a/opensearch-aws-sigv4/spec/spec_helper.rb +++ b/opensearch-aws-sigv4/spec/spec_helper.rb @@ -10,7 +10,7 @@ require 'opensearch-aws-sigv4' require 'rspec' -OPENSEARCH_URL = ENV['TEST_OPENSEARCH_SERVER'] || "http://localhost:#{(ENV['PORT'] || 9200)}" +OPENSEARCH_URL = ENV.fetch('TEST_OPENSEARCH_SERVER', nil) || "http://localhost:#{ENV.fetch('PORT', nil) || 9200}" raise URI::InvalidURIError unless OPENSEARCH_URL =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/ RSpec.configure do |config| diff --git a/opensearch-aws-sigv4/spec/unit/sigv4_client_spec.rb b/opensearch-aws-sigv4/spec/unit/sigv4_client_spec.rb index 1dfe2a3ed..0f3a1dfac 100644 --- a/opensearch-aws-sigv4/spec/unit/sigv4_client_spec.rb +++ b/opensearch-aws-sigv4/spec/unit/sigv4_client_spec.rb @@ -16,7 +16,8 @@ described_class.new( { host: 'http://localhost:9200', transport_options: { ssl: { verify: false } } }, - signer) + signer + ) end let(:signer) do @@ -37,7 +38,7 @@ context 'when a Sigv4 Signer is provided' do it 'does NOT raise any error' do - expect { client }.to_not raise_error + expect { client }.not_to raise_error end end end @@ -45,25 +46,25 @@ describe '#perform_request' do let(:response) { { body: 'Response Body' } } let(:transport_double) do - _double = instance_double('OpenSearch::Transport::Client', perform_request: response) + _double = instance_double(OpenSearch::Transport::Client, perform_request: response) _double.stub_chain(:transport, :hosts, :dig).and_return('localhost') _double end let(:signed_headers) do { 'authorization' => 'AWS4-HMAC-SHA256 Credential=key_id/20220101/us-west-2/es/aws4_request, '\ - 'SignedHeaders=host;x-amz-content-sha256;x-amz-date, ' \ - 'Signature=9c4c690110483308f62a91c2ca873857750bca2607ba1aabdae0d2303950310a', + 'SignedHeaders=host;x-amz-content-sha256;x-amz-date, ' \ + 'Signature=9c4c690110483308f62a91c2ca873857750bca2607ba1aabdae0d2303950310a', 'host' => 'localhost', 'x-amz-content-sha256' => 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', 'x-amz-date' => '20220101T000000Z' } end - before(:each) do + before do Timecop.freeze(Time.utc(2022)) client.transport = transport_double end - after(:each) { Timecop.return } + after { Timecop.return } it 'signs the request before passing it to @transport' do output = client.perform_request('GET', '/', {}, '', {}) @@ -72,7 +73,7 @@ end it 'skips the opensearch verification' do - expect(client).to_not receive(:open_search_validation_request) + expect(client).not_to receive(:open_search_validation_request) client.perform_request('GET', '/_stats', {}, '', {}) end end diff --git a/opensearch-dsl/Gemfile b/opensearch-dsl/Gemfile index 4ea5e5d99..3a512554e 100644 --- a/opensearch-dsl/Gemfile +++ b/opensearch-dsl/Gemfile @@ -29,16 +29,16 @@ source 'https://rubygems.org' # Specify your gem's dependencies in opensearch-dsl.gemspec gemspec -if File.exist? File.expand_path('../../opensearch-ruby/opensearch-ruby.gemspec', __FILE__) - gem 'opensearch-ruby', path: File.expand_path('../../opensearch-ruby', __FILE__), require: false +if File.exist? File.expand_path('../opensearch-ruby/opensearch-ruby.gemspec', __dir__) + gem 'opensearch-ruby', path: File.expand_path('../opensearch-ruby', __dir__), require: false end -if File.exist? File.expand_path('../../opensearch-transport', __FILE__) - gem 'opensearch-transport', path: File.expand_path('../../opensearch-transport', __FILE__), require: true +if File.exist? File.expand_path('../opensearch-transport', __dir__) + gem 'opensearch-transport', path: File.expand_path('../opensearch-transport', __dir__), require: true end -if File.exist? File.expand_path('../../opensearch-api', __FILE__) - gem 'opensearch-api', path: File.expand_path('../../opensearch-api', __FILE__), require: false +if File.exist? File.expand_path('../opensearch-api', __dir__) + gem 'opensearch-api', path: File.expand_path('../opensearch-api', __dir__), require: false end group :development do diff --git a/opensearch-dsl/Rakefile b/opensearch-dsl/Rakefile index b30ee7b3f..d4dc13140 100644 --- a/opensearch-dsl/Rakefile +++ b/opensearch-dsl/Rakefile @@ -24,10 +24,10 @@ # specific language governing permissions and limitations # under the License. -require "bundler/gem_tasks" +require 'bundler/gem_tasks' -task(:default) { system "rake --tasks" } -task :test => 'test:unit' +task(:default) { system 'rake --tasks' } +task test: 'test:unit' # ----- Test tasks ------------------------------------------------------------ @@ -35,8 +35,7 @@ require 'rake/testtask' require 'rspec/core/rake_task' namespace :test do - - desc "Wait for OpenSearch to be in a green state" + desc 'Wait for OpenSearch to be in a green state' task :wait_for_green do sh '../scripts/wait-cluster.sh' end @@ -45,33 +44,32 @@ namespace :test do Rake::TestTask.new(:unit) do |test| test.libs << 'lib' << 'test' - test.test_files = FileList["test/unit/**/*_test.rb"] - test.deps = [ :spec ] + test.test_files = FileList['test/unit/**/*_test.rb'] + test.deps = [:spec] test.verbose = false test.warning = false end Rake::TestTask.new(:integration) do |test| - test.deps = [ :wait_for_green ] + test.deps = [:wait_for_green] test.libs << 'lib' << 'test' - test.test_files = FileList["test/integration/**/*_test.rb"] + test.test_files = FileList['test/integration/**/*_test.rb'] test.verbose = false test.warning = false end - desc "Run unit and integration tests" + desc 'Run unit and integration tests' task :all do Rake::Task['test:unit'].invoke Rake::Task['test:integration'].invoke end - end # ----- Documentation tasks --------------------------------------------------- require 'yard' YARD::Rake::YardocTask.new(:doc) do |t| - t.options = %w| --embed-mixins --markup=markdown | + t.options = %w[--embed-mixins --markup=markdown] end # ----- Code analysis tasks --------------------------------------------------- @@ -109,33 +107,35 @@ namespace :generate do ... DESC - task :source, [:type, :name, :option_methods] do |task, options| - begin - query = URI.escape("#{options[:name]} #{options[:type]}") - response = Net::HTTP.get('search.opensearch.org', "/search/?q=#{query}") - hits = JSON.load(response)['hits']['hits'] - - if hit = hits.first - doc_url = ("http://opensearch.org" + hit['fields']['url']).gsub(/#.+$/, '') if hit['_score'] > 0.2 + task :source, [:type, :name, :option_methods] do |_task, options| + unless ENV['NOCRAWL'] + begin + query = URI.escape("#{options[:name]} #{options[:type]}") + response = Net::HTTP.get('search.opensearch.org', "/search/?q=#{query}") + hits = JSON.load(response)['hits']['hits'] + + if (hit = hits.first) && (hit['_score'] > 0.2) + doc_url = ('http://opensearch.org' + hit['fields']['url']).gsub(/#.+$/, '') + end + rescue Exception => e + puts "[!] ERROR: #{e.inspect}" end - rescue Exception => e - puts "[!] ERROR: #{e.inspect}" - end unless ENV['NOCRAWL'] + end case options[:type] - when /query/ - module_name = 'Queries' - path_name = 'queries' - include_module = 'BaseComponent' - when /filter/ - module_name = 'Filters' - path_name = 'filters' - include_module = 'BaseComponent' - when /agg/ - module_name = 'Aggregations' - path_name = 'aggregations' - include_module = 'BaseAggregationComponent' - else raise ArgumentError, "Unknown DSL type [#{options[:type]}]" + when /query/ + module_name = 'Queries' + path_name = 'queries' + include_module = 'BaseComponent' + when /filter/ + module_name = 'Filters' + path_name = 'filters' + include_module = 'BaseComponent' + when /agg/ + module_name = 'Aggregations' + path_name = 'aggregations' + include_module = 'BaseAggregationComponent' + else raise ArgumentError, "Unknown DSL type [#{options[:type]}]" end name = options[:name].downcase @@ -143,7 +143,7 @@ namespace :generate do class_name = options[:name].split('_').map(&:capitalize).join option_methods = options[:option_methods].to_s.split('/').reduce('') do |sum, item| - sum << " " + sum << ' ' sum << "option_method :#{item}" sum << "\n" unless item == options[:option_methods].to_s.split('/').last sum @@ -176,13 +176,14 @@ namespace :generate do if options[:option_methods].to_s.empty? test_option_methods = '' else - setup = "\n" + options[:option_methods].to_s.split('/').reduce('') do |sum,item| - sum << " subject.#{item} 'bar'\n"; sum + setup = "\n" + options[:option_methods].to_s.split('/').reduce('') do |sum, item| + sum << " subject.#{item} 'bar'\n" + sum end asserts = "\n assert_equal %w[ #{options[:option_methods].to_s.split('/').sort.join(' ')} ],\n subject.to_hash[:#{name}][:foo].keys.map(&:to_s).sort" asserts << "\n assert_equal 'bar', subject.to_hash[:#{name}][:foo][:#{options[:option_methods].to_s.split('/').first}]" - test_option_methods = <<-RUBY.gsub(/^ /, '') + test_option_methods = <<-RUBY.gsub(/^ /, '') should "have option methods" do subject = #{class_name}.new :foo @@ -224,8 +225,8 @@ namespace :generate do source_full_path = File.expand_path("../lib/opensearch/dsl/search/#{path_name}/#{name}.rb", __FILE__) test_full_path = File.expand_path("../test/unit/#{path_name}/#{name}_test.rb", __FILE__) - puts '-'*80, "Source: #{source_full_path}", '-'*80, "\n", CodeRay.scan(source, :ruby).terminal, "\n\n" - puts '-'*80, "Test: #{test_full_path}", '-'*80, "\n", CodeRay.scan(test, :ruby).terminal, "\n" + puts '-' * 80, "Source: #{source_full_path}", '-' * 80, "\n", CodeRay.scan(source, :ruby).terminal, "\n\n" + puts '-' * 80, "Test: #{test_full_path}", '-' * 80, "\n", CodeRay.scan(test, :ruby).terminal, "\n" File.open(source_full_path, 'w') { |file| file << source } diff --git a/opensearch-dsl/lib/opensearch/dsl.rb b/opensearch-dsl/lib/opensearch/dsl.rb index 1d35fcdb8..86237d4c0 100644 --- a/opensearch-dsl/lib/opensearch/dsl.rb +++ b/opensearch-dsl/lib/opensearch/dsl.rb @@ -38,14 +38,13 @@ require 'opensearch/dsl/search/options' require 'opensearch/dsl/search/suggest' -Dir[ File.expand_path('../dsl/search/queries/**/*.rb', __FILE__) ].each { |f| require f } -Dir[ File.expand_path('../dsl/search/filters/**/*.rb', __FILE__) ].each { |f| require f } -Dir[ File.expand_path('../dsl/search/aggregations/**/*.rb', __FILE__) ].each { |f| require f } +Dir[File.expand_path('dsl/search/queries/**/*.rb', __dir__)].each { |f| require f } +Dir[File.expand_path('dsl/search/filters/**/*.rb', __dir__)].each { |f| require f } +Dir[File.expand_path('dsl/search/aggregations/**/*.rb', __dir__)].each { |f| require f } require 'opensearch/dsl/search' module OpenSearch - # The main module, which can be included into your own class or namespace, # to provide the DSL methods. # diff --git a/opensearch-dsl/lib/opensearch/dsl/search.rb b/opensearch-dsl/lib/opensearch/dsl/search.rb index 065caed25..532acdb34 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search.rb @@ -26,12 +26,10 @@ module OpenSearch module DSL - # Provides DSL methods for building the search definition # (queries, filters, aggregations, sorting, etc) # module Search - # Initialize a new Search object # # @example Building a search definition declaratively @@ -62,11 +60,13 @@ def search(*args, &block) # Wraps the whole search definition (queries, filters, aggregations, sorting, etc) # class Search - attr_reader :aggregations + attr_accessor :aggregations def initialize(*args, &block) - @options = Options.new *args - block.arity < 1 ? self.instance_eval(&block) : block.call(self) if block + @options = Options.new(*args) + if block + block.arity < 1 ? instance_eval(&block) : block.call(self) + end end # DSL method for building or accessing the `query` part of a search definition @@ -74,15 +74,14 @@ def initialize(*args, &block) # @return [self, {Query}] # def query(*args, &block) - case - when block - @query = Query.new(*args, &block) - self - when !args.empty? - @query = args.first - self - else - @query + if block + @query = Query.new(*args, &block) + self + elsif !args.empty? + @query = args.first + self + else + @query end end @@ -97,15 +96,14 @@ def query=(value) # @return [self] # def filter(*args, &block) - case - when block - @filter = Filter.new(*args, &block) - self - when !args.empty? - @filter = args.first - self - else - @filter + if block + @filter = Filter.new(*args, &block) + self + elsif !args.empty? + @filter = args.first + self + else + @filter end end @@ -120,15 +118,14 @@ def filter=(value) # @return [self] # def post_filter(*args, &block) - case - when block - @post_filter = Filter.new(*args, &block) - self - when !args.empty? - @post_filter = args.first - self - else - @post_filter + if block + @post_filter = Filter.new(*args, &block) + self + elsif !args.empty? + @post_filter = args.first + self + else + @post_filter end end @@ -156,9 +153,6 @@ def aggregation(*args, &block) # Set the aggregations part of a search definition # - def aggregations=(value) - @aggregations = value - end # DSL method for building the `highlight` part of a search definition # @@ -188,48 +182,46 @@ def sort(*args, &block) # Set the sort part of a search definition # - def sort=(value) - @sort = value - end + attr_writer :sort # DSL method for building the `stored_fields` part of a search definition # # @return [self] # - def stored_fields(value=nil) + def stored_fields(value = nil) if value @stored_fields = value self else @stored_fields end - end; alias_method :stored_fields=, :stored_fields + end; alias stored_fields= stored_fields # DSL method for building the `size` part of a search definition # # @return [self] # - def size(value=nil) + def size(value = nil) if value @size = value self else @size end - end; alias_method :size=, :size + end; alias size= size # DSL method for building the `from` part of a search definition # # @return [self] # - def from(value=nil) + def from(value = nil) if value @from = value self else @from end - end; alias_method :from=, :from + end; alias from= from # DSL method for building the `suggest` part of a search definition # @@ -248,9 +240,7 @@ def suggest(*args, &block) # Set the suggest part of a search definition # - def suggest=(value) - @suggest = value - end + attr_writer :suggest # Delegates to the methods provided by the {Options} class # @@ -272,12 +262,16 @@ def to_hash hash.update(query: @query.to_hash) if @query hash.update(filter: @filter.to_hash) if @filter hash.update(post_filter: @post_filter.to_hash) if @post_filter - hash.update(aggregations: @aggregations.reduce({}) { |sum,item| sum.update item.first => item.last.to_hash }) if @aggregations + if @aggregations + hash.update(aggregations: @aggregations.reduce({}) do |sum, item| + sum.update item.first => item.last.to_hash + end) + end hash.update(sort: @sort.to_hash) if @sort hash.update(size: @size) if @size hash.update(stored_fields: @stored_fields) if @stored_fields hash.update(from: @from) if @from - hash.update(suggest: @suggest.reduce({}) { |sum,item| sum.update item.last.to_hash }) if @suggest + hash.update(suggest: @suggest.reduce({}) { |sum, item| sum.update item.last.to_hash }) if @suggest hash.update(highlight: @highlight.to_hash) if @highlight hash.update(@options) unless @options.empty? hash diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregation.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregation.rb index c750c8411..7ea61fd5c 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregation.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregation.rb @@ -27,14 +27,13 @@ module OpenSearch module DSL module Search - # Contains the classes for OpenSearch aggregations # - module Aggregations;end + module Aggregations; end class AggregationsCollection < Hash def to_hash - @hash ||= Hash[map { |k,v| [k, v.to_hash] }] + @hash ||= map { |k, v| [k, v.to_hash] }.to_h end end @@ -42,7 +41,7 @@ def to_hash # # class Aggregation - def initialize(*args, &block) + def initialize(*_args, &block) @block = block end @@ -53,7 +52,7 @@ def initialize(*args, &block) def method_missing(name, *args, &block) klass = Utils.__camelize(name) if Aggregations.const_defined? klass - @value = Aggregations.const_get(klass).new *args, &block + @value = Aggregations.const_get(klass).new(*args, &block) else raise NoMethodError, "undefined method '#{name}' for #{self}" end @@ -80,7 +79,9 @@ def aggregations # @api private # def call - @block.arity < 1 ? self.instance_eval(&@block) : @block.call(self) if @block && ! @_block_called + if @block && !@_block_called + @block.arity < 1 ? instance_eval(&@block) : @block.call(self) + end @_block_called = true self end @@ -89,22 +90,20 @@ def call # # @return [Hash] # - def to_hash(options={}) + def to_hash(_options = {}) call if @value - case - when @value.respond_to?(:to_hash) - @value.to_hash - else - @value + if @value.respond_to?(:to_hash) + @value.to_hash + else + @value end else {} end end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/avg.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/avg.rb index 2b21d9c58..8785447d0 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/avg.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/avg.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A single-value metric aggregation which returns the average of numeric values # # @example @@ -44,7 +43,6 @@ module Aggregations class Avg include BaseComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/cardinality.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/cardinality.rb index ed2da4609..d51f9bd73 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/cardinality.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/cardinality.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A single-value metric aggregation which returns the approximate count of distinct values # # @example @@ -51,7 +50,6 @@ class Cardinality option_method :script option_method :params end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/children.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/children.rb index 0fa78594d..a793c840d 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/children.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/children.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A single-bucket aggregation which allows to aggregate from buckets on parent documents # to buckets on the children documents # @@ -58,7 +57,6 @@ class Children option_method :type end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/composite.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/composite.rb index f518cff28..90145974c 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/composite.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/composite.rb @@ -45,8 +45,8 @@ module Aggregations # end # end # end - # - # + # + # class Composite include BaseAggregationComponent @@ -54,7 +54,7 @@ class Composite option_method :sources option_method :after - def to_hash(_options={}) + def to_hash(_options = {}) super # remove :after if no value is given @hash[name.to_sym].delete(:after) if @hash[name.to_sym].is_a?(Hash) && @hash[name.to_sym][:after].nil? diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/date_histogram.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/date_histogram.rb index 1c8d790a7..6c82d7da5 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/date_histogram.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/date_histogram.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A multi-bucket aggregation which returns a histogram for date fields # # @example @@ -59,7 +58,6 @@ class DateHistogram option_method :extended_bounds option_method :order end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/date_range.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/date_range.rb index cd178dfa7..685be3d1e 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/date_range.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/date_range.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A multi-bucket aggregation which returns document counts for custom date ranges # # @example diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/extended_stats.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/extended_stats.rb index f117c1ac2..1b7dea59a 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/extended_stats.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/extended_stats.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A multi-value metrics aggregation which returns the extended statistical information on numeric values # # @example @@ -43,7 +42,6 @@ module Aggregations class ExtendedStats include BaseComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/filter.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/filter.rb index bf1e347f0..028b8474c 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/filter.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/filter.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # Defines a single bucket with documents matching the provided filter, # usually to define scope for a nested aggregation # @@ -49,7 +48,6 @@ module Aggregations class Filter include BaseAggregationComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/filters.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/filters.rb index 7d6d3c601..4cdb02d49 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/filters.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/filters.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A multi-bucket aggregation which defines multiple buckets matching the provided filters, # usually to define scope for a nested aggregation # @@ -54,7 +53,6 @@ class Filters option_method :filters end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/geo_bounds.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/geo_bounds.rb index 16139a981..35838a51e 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/geo_bounds.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/geo_bounds.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # An aggregation which will calculate the smallest bounding box required to encapsulate # all of the documents matching the query # @@ -63,7 +62,6 @@ class GeoBounds option_method :field option_method :wrap_longitude end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/geo_distance.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/geo_distance.rb index c3585d86d..b227c0718 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/geo_distance.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/geo_distance.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A multi-bucket aggregation which will return document counts for distance perimeters, # defined as ranges # @@ -58,7 +57,6 @@ class GeoDistance option_method :unit option_method :distance_type end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/geohash_grid.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/geohash_grid.rb index 857bc57fd..b714c058e 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/geohash_grid.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/geohash_grid.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A multi-bucket aggregation which will return document counts for geohash grid cells # # @example @@ -54,7 +53,6 @@ class GeohashGrid option_method :size option_method :shard_size end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/global.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/global.rb index c707de1d4..914f93909 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/global.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/global.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # Defines a single bucket of all the documents matching a query # # @example @@ -47,7 +46,6 @@ module Aggregations class Global include BaseAggregationComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/histogram.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/histogram.rb index 905d57e27..91feb8e06 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/histogram.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/histogram.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A multi-bucket aggregation which returns document counts for a defined numerical interval # # @example @@ -54,7 +53,6 @@ class Histogram option_method :order option_method :keyed end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/ip_range.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/ip_range.rb index c84935e49..4b6b61c83 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/ip_range.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/ip_range.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A multi-bucket aggregation which returns document counts for defined IP ranges # # @example @@ -50,7 +49,6 @@ class IpRange option_method :field option_method :ranges end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/max.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/max.rb index cfe36a26d..7d747a0b8 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/max.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/max.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A single-value metric aggregation which returns the maximum value from numeric values # # @example @@ -44,7 +43,6 @@ module Aggregations class Max include BaseComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/min.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/min.rb index 06133a283..7ef1fd904 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/min.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/min.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A single-value metric aggregation which returns the minimum value from numeric values # # @example @@ -44,7 +43,6 @@ module Aggregations class Min include BaseComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/missing.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/missing.rb index 0418b54f7..bdcc33e70 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/missing.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/missing.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A single bucket aggregation that creates a bucket of all documents # which are missing a value for the field # @@ -54,7 +53,6 @@ class Missing option_method :field end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/nested.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/nested.rb index 5f0073637..a8694534d 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/nested.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/nested.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A single-bucket aggregation which allows to aggregate on nested fields # # @example @@ -52,7 +51,6 @@ class Nested option_method :path end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/percentile_ranks.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/percentile_ranks.rb index ff561e705..4f8c700fb 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/percentile_ranks.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/percentile_ranks.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A multi-value metrics aggregation which calculates percentile ranks on numeric values # # @example @@ -53,7 +52,6 @@ class PercentileRanks option_method :params option_method :compression end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/percentiles.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/percentiles.rb index 74cd7247c..f863263ae 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/percentiles.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/percentiles.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A multi-value metrics aggregation which calculates percentiles on numeric values # # @example @@ -52,7 +51,6 @@ class Percentiles option_method :params option_method :compression end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/avg_bucket.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/avg_bucket.rb index fdc51c460..833ba61bb 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/avg_bucket.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/avg_bucket.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A sibling pipeline aggregation which calculates the (mean) average value of a specified metric in a sibling aggregation. # # @example Passing the options as a Hash diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/bucket_script.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/bucket_script.rb index aec8eb6a6..619bd6266 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/bucket_script.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/bucket_script.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A parent pipeline aggregation which executes a script which can perform per bucket computations on specified metrics in the parent multi-bucket aggregation. # # @example Passing the options as a Hash diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/bucket_selector.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/bucket_selector.rb index 957c16335..35485dab7 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/bucket_selector.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/bucket_selector.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A parent pipeline aggregation which executes a script which determines whether the current bucket will be retained in the parent multi-bucket aggregation. # # @example Passing the options as a Hash diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/bucket_sort.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/bucket_sort.rb index 35a63b5b5..62785b989 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/bucket_sort.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/bucket_sort.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A parent pipeline aggregation which sorts the buckets of its parent multi-bucket aggregation. # # @example Passing the options as a Hash @@ -96,9 +95,7 @@ def sort(*args, &block) def to_hash call - if @aggregations - @hash[:aggregations] = @aggregations.to_hash - end + @hash[:aggregations] = @aggregations.to_hash if @aggregations @hash[name].merge!(sort: @sort.to_hash) if @sort @hash diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/cumulative_sum.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/cumulative_sum.rb index 0047dde5a..f395b5b0b 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/cumulative_sum.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/cumulative_sum.rb @@ -28,8 +28,7 @@ module OpenSearch module DSL module Search module Aggregations - - # A parent pipeline aggregation which calculates the cumulative sum of a specified metric in a parent histogram (or date_histogram) aggregation. + # A parent pipeline aggregation which calculates the cumulative sum of a specified metric in a parent histogram (or date_histogram) aggregation. # # @example Passing the options as a Hash # diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/derivative.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/derivative.rb index 79a993390..b26e62d22 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/derivative.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/derivative.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A parent pipeline aggregation which calculates the derivative of a specified metric in a parent histogram (or date_histogram) aggregation. # # @example Passing the options as a Hash diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/extended_stats_bucket.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/extended_stats_bucket.rb index dbd721f30..e138c0c62 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/extended_stats_bucket.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/extended_stats_bucket.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A sibling pipeline aggregation which calculates a variety of stats across all bucket of a specified metric in a sibling aggregation. The specified metric must be numeric and the sibling aggregation must be a multi-bucket aggregation. # # @example Passing the options as a Hash diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/max_bucket.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/max_bucket.rb index 3442829c7..378d81399 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/max_bucket.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/max_bucket.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A sibling pipeline aggregation which identifies the bucket(s) with the maximum value of a specified metric in a sibling aggregation and outputs both the value and the key(s) of the bucket(s). # # @example Passing the options as a Hash diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/min_bucket.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/min_bucket.rb index 11f9ccdac..a15f76cbd 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/min_bucket.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/min_bucket.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A sibling pipeline aggregation which identifies the bucket(s) with the minimum value of a specified metric in a sibling aggregation and outputs both the value and the key(s) of the bucket(s). # # @example Passing the options as a Hash diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/moving_avg.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/moving_avg.rb index cb05e6a31..d637fead4 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/moving_avg.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/moving_avg.rb @@ -28,8 +28,7 @@ module OpenSearch module DSL module Search module Aggregations - - # Given an ordered series of data, the Moving Average aggregation will slide a window across the data and emit the average value of that window. + # Given an ordered series of data, the Moving Average aggregation will slide a window across the data and emit the average value of that window. # # @example Passing the options as a Hash # diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/percentiles_bucket.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/percentiles_bucket.rb index ce8847654..03bf47649 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/percentiles_bucket.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/percentiles_bucket.rb @@ -28,8 +28,7 @@ module OpenSearch module DSL module Search module Aggregations - - # A sibling pipeline aggregation which calculates percentiles across all bucket of a specified metric in a sibling aggregation. + # A sibling pipeline aggregation which calculates percentiles across all bucket of a specified metric in a sibling aggregation. # # @example Passing the options as a Hash # diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/serial_diff.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/serial_diff.rb index 12267443c..bf92970fb 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/serial_diff.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/serial_diff.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # Serial differencing is a technique where values in a time series are subtracted from itself at different time lags or periods. # # @example Passing the options as a Hash diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/stats_bucket.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/stats_bucket.rb index 991898eb5..e9364cacf 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/stats_bucket.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/stats_bucket.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A sibling pipeline aggregation which calculates a variety of stats across all bucket of a specified metric in a sibling aggregation. # # @example Passing the options as a Hash diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/sum_bucket.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/sum_bucket.rb index 7d87a06de..d843e93e9 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/sum_bucket.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/pipeline/sum_bucket.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A sibling pipeline aggregation which calculates the sum across all bucket of a specified metric in a sibling aggregation. # # @example Passing the options as a Hash diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/range.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/range.rb index c8267c70e..d0396ee14 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/range.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/range.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A multi-bucket aggregation which returns document counts for custom numerical ranges, # which define the buckets # @@ -72,7 +71,6 @@ def key(key, value) self end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/reverse_nested.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/reverse_nested.rb index bd1a4ada3..71ead4ae7 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/reverse_nested.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/reverse_nested.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A single-bucket aggregation which allows to aggregate on "parent" documents # from the nested documents # @@ -56,7 +55,6 @@ module Aggregations class ReverseNested include BaseAggregationComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/scripted_metric.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/scripted_metric.rb index a54288dee..80e299646 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/scripted_metric.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/scripted_metric.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A metric aggregation which uses scripts for the computation # # @example @@ -58,7 +57,6 @@ class ScriptedMetric option_method :params option_method :lang end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/significant_terms.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/significant_terms.rb index 489bc6fb3..7e33e17ee 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/significant_terms.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/significant_terms.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A multi-bucket aggregation that returns interesting or unusual occurrences of terms in a set # # @example @@ -64,7 +63,6 @@ class SignificantTerms option_method :chi_square option_method :gnd end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/stats.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/stats.rb index b14104619..df6b4671b 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/stats.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/stats.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A multi-value metrics aggregation which returns statistical information on numeric values # # @example Passing the options as a Hash @@ -56,7 +55,6 @@ class Stats option_method :field option_method :script end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/sum.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/sum.rb index 8e552dc03..61f8f85ff 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/sum.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/sum.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A single-value metric aggregation which returns the sum of numeric values # # @example @@ -44,7 +43,6 @@ module Aggregations class Sum include BaseComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/terms.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/terms.rb index cfdd76e59..906df8d19 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/terms.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/terms.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A multi-bucket aggregation which returns the collection of terms and their document counts # # @example Passing the options as a Hash @@ -61,7 +60,6 @@ class Terms option_method :include option_method :exclude end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/top_hits.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/top_hits.rb index 2fef174c2..68c009965 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/top_hits.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/top_hits.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A metric aggregator which returns the most relevant documents per bucket # # @example @@ -54,7 +53,6 @@ class TopHits option_method :size option_method :sort end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/value_count.rb b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/value_count.rb index 76142eb8c..d5c1baaf2 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/aggregations/value_count.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/aggregations/value_count.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Aggregations - # A single-value metric aggregation which returns the number of values for the aggregation scope # # @example @@ -44,7 +43,6 @@ module Aggregations class ValueCount include BaseComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/base_aggregation_component.rb b/opensearch-dsl/lib/opensearch/dsl/search/base_aggregation_component.rb index c970f60ae..30439de92 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/base_aggregation_component.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/base_aggregation_component.rb @@ -27,18 +27,15 @@ module OpenSearch module DSL module Search - # Module containing common functionality for aggregation DSL classes # module BaseAggregationComponent - def self.included(base) base.__send__ :include, BaseComponent base.__send__ :include, InstanceMethods end module InstanceMethods - attr_reader :aggregations # Looks up the corresponding class for a method being invoked, and initializes it @@ -48,7 +45,7 @@ module InstanceMethods def method_missing(name, *args, &block) klass = Utils.__camelize(name) if Aggregations.const_defined? klass - @value = Aggregations.const_get(klass).new *args, &block + @value = Aggregations.const_get(klass).new(*args, &block) else raise NoMethodError, "undefined method '#{name}' for #{self}" end @@ -70,21 +67,16 @@ def aggregation(*args, &block) # # @return [Hash] # - def to_hash(options={}) + def to_hash(_options = {}) call - @hash = { name => @args } unless @hash && @hash[name] && ! @hash[name].empty? + @hash = { name => @args } unless @hash && @hash[name] && !@hash[name].empty? - if @aggregations - @hash[:aggregations] = @aggregations.to_hash - end + @hash[:aggregations] = @aggregations.to_hash if @aggregations @hash end end - end - end end end - diff --git a/opensearch-dsl/lib/opensearch/dsl/search/base_component.rb b/opensearch-dsl/lib/opensearch/dsl/search/base_component.rb index ba598ac4b..d3f7ea179 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/base_component.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/base_component.rb @@ -27,7 +27,6 @@ module OpenSearch module DSL module Search - # Module containing common functionality for DSL classes # module BaseComponent @@ -68,12 +67,12 @@ def self.included(base) # q.to_hash # # => {:mycustomquery=>{:foo=>{:custom=>"TEST"}}} # - def option_method(name, block=nil) + def option_method(name, block = nil) option_methods << name if block - self.__send__ :define_method, name, &block + __send__ :define_method, name, &block else - self.__send__ :define_method, name do |*args| + __send__ :define_method, name do |*args| # 1. Component has empty @args (ie. no user supplied name or @hash value) if @args && @args.respond_to?(:to_hash) && @args.empty? @hash[self.name.to_sym].update name.to_sym => args.first @@ -96,7 +95,6 @@ def initialize(*args, &block) end module ClassMethods - # Get or set the name for the DSL class # # @example Set the index name for the `Article` model and re-evaluate it on each call @@ -109,15 +107,15 @@ module ClassMethods # MyQuery.name # # => :my_special_query # - def name(value=nil) + def name(value = nil) if value @name = value.to_sym else @name ||= begin - value = self.to_s.split('::').last - value.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2') - value.gsub!(/([a-z\d])([A-Z])/,'\1_\2') - value.tr!("-", "_") + value = to_s.split('::').last + value.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2') + value.gsub!(/([a-z\d])([A-Z])/, '\1_\2') + value.tr!('-', '_') value.downcase! value.to_sym end @@ -136,7 +134,6 @@ def option_methods end module InstanceMethods - # Return the name for instance of the DSL class # # @return [String] @@ -150,7 +147,9 @@ def name # @return [self] # def call - @block.arity < 1 ? self.instance_eval(&@block) : @block.call(self) if @block + if @block + @block.arity < 1 ? instance_eval(&@block) : @block.call(self) + end self end @@ -166,24 +165,23 @@ def empty? # # @return [Hash] # - def to_hash(options={}) - case - # 1. Create hash from the block - when @block - @hash = (@args && ! @args.empty?) ? { name => { @args => {} } } : { name => {} } - call - @hash[self.name.to_sym].update @options unless @options.empty? - @hash + def to_hash(_options = {}) + # 1. Create hash from the block + if @block + @hash = @args && !@args.empty? ? { name => { @args => {} } } : { name => {} } + call + @hash[name.to_sym].update @options unless @options.empty? + @hash # 2. Hash created with option methods - when @hash[self.name.to_sym] && ! @args.is_a?(Hash) && @hash[self.name.to_sym][@args] - @hash[self.name.to_sym].update @options unless @options.empty? - @hash + elsif @hash[name.to_sym] && !@args.is_a?(Hash) && @hash[name.to_sym][@args] + @hash[name.to_sym].update @options unless @options.empty? + @hash # 3. Hash passsed as @args - when @hash[self.name.to_sym] && @args.respond_to?(:to_hash) && ! @args.empty? - { name => @args.to_hash } + elsif @hash[name.to_sym] && @args.respond_to?(:to_hash) && !@args.empty? + { name => @args.to_hash } # 4. Hash already built - else - @hash + else + @hash end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/base_compound_filter_component.rb b/opensearch-dsl/lib/opensearch/dsl/search/base_compound_filter_component.rb index f216dd16b..499251315 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/base_compound_filter_component.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/base_compound_filter_component.rb @@ -27,7 +27,6 @@ module OpenSearch module DSL module Search - # Module containing common functionality for a "compound" (wrapping) filters, such as `and`, `or`, `not` # module BaseCompoundFilterComponent @@ -54,7 +53,9 @@ module InstanceMethods # @api private # def call - @block.arity < 1 ? self.instance_eval(&@block) : @block.call(self) if @block && ! @_block_called + if @block && !@_block_called + @block.arity < 1 ? instance_eval(&@block) : @block.call(self) + end @_block_called = true self end @@ -65,11 +66,10 @@ def call # # @return [Hash] # - def to_hash(options={}) - case - when @value.empty? && ! @block + def to_hash(options = {}) + if @value.empty? && !@block @hash = super - when @block + elsif @block call @hash = { name.to_sym => @value.map { |i| i.to_hash } } else @@ -88,7 +88,7 @@ def each(&block) def slice(*args) @value.slice(*args) - end; alias :[] :slice + end; alias [] slice def size @value.size diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filter.rb b/opensearch-dsl/lib/opensearch/dsl/search/filter.rb index 9e57aad17..b9003147e 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filter.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filter.rb @@ -27,16 +27,15 @@ module OpenSearch module DSL module Search - # Contains the classes for OpenSearch filters # - module Filters;end + module Filters; end # Wraps the `filter` part of a search definition, aggregation, etc # # class Filter - def initialize(*args, &block) + def initialize(*_args, &block) @block = block end @@ -47,7 +46,7 @@ def initialize(*args, &block) def method_missing(name, *args, &block) klass = Utils.__camelize(name) if Filters.const_defined? klass - @value = Filters.const_get(klass).new *args, &block + @value = Filters.const_get(klass).new(*args, &block) else raise NoMethodError, "undefined method '#{name}' for #{self}" end @@ -58,7 +57,9 @@ def method_missing(name, *args, &block) # @return [self] # def call - @block.arity < 1 ? self.instance_eval(&@block) : @block.call(self) if @block + if @block + @block.arity < 1 ? instance_eval(&@block) : @block.call(self) + end self end @@ -66,7 +67,7 @@ def call # # @return [Hash] # - def to_hash(options={}) + def to_hash(_options = {}) call if @value @value.to_hash @@ -75,7 +76,6 @@ def to_hash(options={}) end end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/and.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/and.rb index 2895d99d3..6128c73b1 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/and.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/and.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A compound filter which matches documents by an intersection of individual filters. # # @note Since `and` is a keyword in Ruby, use the `_and` method in DSL definitions diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/bool.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/bool.rb index 1983ca0ae..a0b0206b5 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/bool.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/bool.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A compound filter which matches documents based on combinations of filters # # @example Defining a bool filter with multiple conditions @@ -98,7 +97,6 @@ def to_hash @hash end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/exists.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/exists.rb index 09501c32c..5ee05636a 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/exists.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/exists.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns documents which have a non-`null` value in the specified field # (ie. the reverse of the `missing` filter) # @@ -51,7 +50,6 @@ class Exists option_method :field end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_bounding_box.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_bounding_box.rb index f99d7119d..f526643fd 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_bounding_box.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_bounding_box.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns documents which fall into a "box" of the specified geographical coordinates # # @example @@ -64,7 +63,6 @@ class GeoBoundingBox option_method :bottom option_method :right end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_distance.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_distance.rb index 7978bc014..800e564c6 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_distance.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_distance.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns documents which fall into a specified geographical distance # # @example Define the filter with a hash @@ -66,17 +65,16 @@ module Filters class GeoDistance include BaseComponent - option_method :distance, lambda { |*args| @hash[self.name.to_sym].update distance: args.pop } - option_method :distance_type, lambda { |*args| @hash[self.name.to_sym].update distance_type: args.pop } - option_method :lat, lambda { |*args| @hash[self.name.to_sym][@args].update lat: args.pop } - option_method :lon, lambda { |*args| @hash[self.name.to_sym][@args].update lon: args.pop } + option_method :distance, ->(*args) { @hash[name.to_sym].update distance: args.pop } + option_method :distance_type, ->(*args) { @hash[name.to_sym].update distance_type: args.pop } + option_method :lat, ->(*args) { @hash[name.to_sym][@args].update lat: args.pop } + option_method :lon, ->(*args) { @hash[name.to_sym][@args].update lon: args.pop } def initialize(*args, &block) super - @hash[self.name.to_sym] = { @args => {} } unless @args.empty? + @hash[name.to_sym] = { @args => {} } unless @args.empty? end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_distance_range.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_distance_range.rb index a757087ab..a939965da 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_distance_range.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_distance_range.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns documents which fall into a specified geographical distance range # # @example Define the filter with a hash @@ -51,7 +50,6 @@ class GeoDistanceRange option_method :lat option_method :lon end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_polygon.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_polygon.rb index 0d2387af6..030aff998 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_polygon.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_polygon.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns documents which fall into a specified geographical polygon # # @example @@ -60,7 +59,6 @@ class GeoPolygon option_method :points end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_shape.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_shape.rb index 7a96bbc75..abf579d0c 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_shape.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/geo_shape.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns documents which fall into a specified geographical shape # # @example @@ -54,7 +53,6 @@ class GeoShape option_method :shape option_method :indexed_shape end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/geohash_cell.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/geohash_cell.rb index 099d5cb46..343457232 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/geohash_cell.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/geohash_cell.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which translates lat/lon values into a geohash with the specified precision # and returns all documents which fall into it # @@ -56,14 +55,14 @@ module Filters class GeohashCell include BaseComponent - option_method :precision, lambda { |*args| @hash[self.name.to_sym].update precision: args.pop } - option_method :lat, lambda { |*args| @hash[self.name.to_sym][@args].update lat: args.pop } - option_method :lon, lambda { |*args| @hash[self.name.to_sym][@args].update lon: args.pop } - option_method :neighbors, lambda { |*args| @hash[self.name.to_sym].update neighbors: args.pop } + option_method :precision, ->(*args) { @hash[name.to_sym].update precision: args.pop } + option_method :lat, ->(*args) { @hash[name.to_sym][@args].update lat: args.pop } + option_method :lon, ->(*args) { @hash[name.to_sym][@args].update lon: args.pop } + option_method :neighbors, ->(*args) { @hash[name.to_sym].update neighbors: args.pop } def initialize(*args, &block) super - @hash[self.name.to_sym] = { @args => {} } unless @args.empty? + @hash[name.to_sym] = { @args => {} } unless @args.empty? end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/has_child.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/has_child.rb index 8c838b207..53d23dbee 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/has_child.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/has_child.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns parent documents for children documents matching a query or a filter # # @example Return articles where John has commented @@ -84,16 +83,15 @@ def to_hash hash = super if @query _query = @query.respond_to?(:to_hash) ? @query.to_hash : @query - hash[self.name].update(query: _query) + hash[name].update(query: _query) end if @filter _filter = @filter.respond_to?(:to_hash) ? @filter.to_hash : @filter - hash[self.name].update(filter: _filter) + hash[name].update(filter: _filter) end hash end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/has_parent.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/has_parent.rb index cde6a62e1..82a10b7d3 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/has_parent.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/has_parent.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns children documents for parent documents matching a query or a filter # # @example Return comments for articles about Ruby @@ -83,16 +82,15 @@ def to_hash hash = super if @query _query = @query.respond_to?(:to_hash) ? @query.to_hash : @query - hash[self.name].update(query: _query) + hash[name].update(query: _query) end if @filter _filter = @filter.respond_to?(:to_hash) ? @filter.to_hash : @filter - hash[self.name].update(filter: _filter) + hash[name].update(filter: _filter) end hash end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/ids.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/ids.rb index 4cfb3e51e..674f91abc 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/ids.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/ids.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns documents matching the specified IDs # # @example @@ -51,7 +50,6 @@ class Ids option_method :type option_method :values end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/indices.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/indices.rb index 52546090f..ffe540973 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/indices.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/indices.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which executes a custom filter only for documents in specified indices, # and optionally another filter for documents in other indices # @@ -87,16 +86,15 @@ def to_hash hash = super if @filter _filter = @filter.respond_to?(:to_hash) ? @filter.to_hash : @filter - hash[self.name].update(filter: _filter) + hash[name].update(filter: _filter) end if @no_match_filter _no_match_filter = @no_match_filter.respond_to?(:to_hash) ? @no_match_filter.to_hash : @no_match_filter - hash[self.name].update(no_match_filter: _no_match_filter) + hash[name].update(no_match_filter: _no_match_filter) end hash end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/limit.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/limit.rb index b2aae5f46..4e8b6b42c 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/limit.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/limit.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which limits the number of documents to evaluate # # @example @@ -50,7 +49,6 @@ class Limit option_method :value end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/match_all.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/match_all.rb index 48c1f0e7a..90127e18d 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/match_all.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/match_all.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which matches on all documents # # @example @@ -47,7 +46,6 @@ module Filters class MatchAll include BaseComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/missing.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/missing.rb index cbdfdb9b4..83b5e7bb8 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/missing.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/missing.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns documents which have a `null` value in the specified field # (ie. the reverse of the `exists` filter) # @@ -53,7 +52,6 @@ class Missing option_method :existence option_method :null_value end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/nested.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/nested.rb index d53ab3c15..a7f0aea47 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/nested.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/nested.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which executes another filter in the context of a nested document # # @example @@ -77,16 +76,15 @@ def to_hash hash = super if @filter _filter = @filter.respond_to?(:to_hash) ? @filter.to_hash : @filter - hash[self.name].update(filter: _filter) + hash[name].update(filter: _filter) end if @query _query = @query.respond_to?(:to_hash) ? @query.to_hash : @query - hash[self.name].update(query: _query) + hash[name].update(query: _query) end hash end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/not.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/not.rb index 1ab0e6833..f835b45cc 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/not.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/not.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which takes out documents matching a filter from the results # # @note Since `not` is a keyword in Ruby, use the `_not` method in DSL definitions @@ -82,11 +81,10 @@ def method_missing(name, *args, &block) # # @return [Hash] # - def to_hash(options={}) - case - when (! @value || @value.empty?) && ! @block + def to_hash(options = {}) + if (!@value || @value.empty?) && !@block @hash = super - when @block + elsif @block call @hash = { name.to_sym => @value.to_hash } end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/or.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/or.rb index 9322e1404..50a454e40 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/or.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/or.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A compound filter which matches documents by a union of individual filters. # # @note Since `or` is a keyword in Ruby, use the `_or` method in DSL definitions diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/prefix.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/prefix.rb index 04dbe5d30..9fd64f3ce 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/prefix.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/prefix.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns documents where the field value a specified prefix # # @example @@ -48,7 +47,6 @@ module Filters class Prefix include BaseComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/query.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/query.rb index c4d8f2479..a2b41017c 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/query.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/query.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which wraps a query so it can be used as a filter # # @example @@ -68,12 +67,11 @@ def to_hash hash = super if @query _query = @query.respond_to?(:to_hash) ? @query.to_hash : @query - hash[self.name].update(_query) + hash[name].update(_query) end hash end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/range.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/range.rb index bcf896531..b68a1b0f0 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/range.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/range.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns documents that have terms in a specified range # # @example @@ -58,7 +57,6 @@ class Range option_method :time_zone option_method :format end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/regexp.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/regexp.rb index 274df5397..9a391b3d8 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/regexp.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/regexp.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns documents matching the specified regular expression # # @example @@ -53,7 +52,6 @@ class Regexp option_method :value option_method :flags end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/script.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/script.rb index 9bf6ef109..8ad03f51f 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/script.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/script.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns documents matching the criteria defined with a script # # @example @@ -51,7 +50,6 @@ class Script option_method :script option_method :params end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/term.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/term.rb index c46fc6c39..b7fe39de0 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/term.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/term.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns documents matching the specified terms # # @example @@ -50,7 +49,6 @@ module Filters class Term include BaseComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/terms.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/terms.rb index 7be8137d5..44ae4a6b9 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/terms.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/terms.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns documents matching any term from the specified list of terms # # @example @@ -51,7 +50,6 @@ module Filters class Terms include BaseComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/filters/type.rb b/opensearch-dsl/lib/opensearch/dsl/search/filters/type.rb index 6c6bdab33..0b71c41d5 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/filters/type.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/filters/type.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Filters - # A filter which returns documents matching the specified type # # @example @@ -53,7 +52,6 @@ class Type option_method :value end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/highlight.rb b/opensearch-dsl/lib/opensearch/dsl/search/highlight.rb index a1a9f716d..1ea4c384b 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/highlight.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/highlight.rb @@ -27,7 +27,6 @@ module OpenSearch module DSL module Search - # Wraps the `highlight` part of a search definition # # @@ -52,12 +51,13 @@ def initialize(*args, &block) # def fields(value_or_name) value = case value_or_name - when Hash - value_or_name - when Array - value_or_name.reduce({}) { |sum, item| sum.update item.to_sym => {}; sum } - else - end + when Hash + value_or_name + when Array + value_or_name.each_with_object({}) do |item, sum| + sum.update item.to_sym => {} + end + end (@value[:fields] ||= {}).update value self @@ -74,7 +74,7 @@ def fields(value_or_name) # end # end # - def field(name, options={}) + def field(name, options = {}) (@value[:fields] ||= {}).update name.to_sym => options end @@ -82,25 +82,25 @@ def field(name, options={}) # def pre_tags(*value) @value[:pre_tags] = value.flatten - end; alias_method :pre_tags=, :pre_tags + end; alias pre_tags= pre_tags # Specify the closing tags for the highlighted snippets # def post_tags(*value) @value[:post_tags] = value.flatten - end; alias_method :post_tags=, :post_tags + end; alias post_tags= post_tags # Specify the `encoder` option for highlighting # def encoder(value) @value[:encoder] = value - end; alias_method :encoder=, :encoder + end; alias encoder= encoder # Specify the `tags_schema` option for highlighting # def tags_schema(value) @value[:tags_schema] = value - end; alias_method :tags_schema=, :tags_schema + end; alias tags_schema= tags_schema # Convert the definition to a Hash # diff --git a/opensearch-dsl/lib/opensearch/dsl/search/options.rb b/opensearch-dsl/lib/opensearch/dsl/search/options.rb index 241b8ba42..2408a486e 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/options.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/options.rb @@ -27,37 +27,36 @@ module OpenSearch module DSL module Search - # Wraps the "extra" options of a search definition # # class Options - DSL_METHODS = [ - :_source, - :fields, - :script_fields, - :fielddata_fields, - :rescore, - :explain, - :version, - :indices_boost, - :track_scores, - :min_score, - :track_total_hits + DSL_METHODS = %i[ + _source + fields + script_fields + fielddata_fields + rescore + explain + version + indices_boost + track_scores + min_score + track_total_hits ] - def initialize(*args, &block) + def initialize(*_args) @hash = {} end # Defines a method for each valid search definition option # DSL_METHODS.each do |name| - define_method name do |*args, &block| + define_method name do |*args| @hash[name] = args.pop end - define_method name.to_s.gsub(/^_(.*)/, '\1') do |*args, &block| + define_method name.to_s.gsub(/^_(.*)/, '\1') do |*args| @hash[name] = args.pop end end @@ -72,7 +71,7 @@ def empty? # # @return [Hash] # - def to_hash(options={}) + def to_hash(_options = {}) @hash end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/bool.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/bool.rb index 149456879..1199ec870 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/bool.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/bool.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A compound query which matches documents based on combinations of queries # # @example Defining a bool query with multiple conditions diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/boosting.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/boosting.rb index ee669bdc6..c01145fb1 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/boosting.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/boosting.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which will decrease the score of documents matching the `negative` query # # @example @@ -52,7 +51,6 @@ class Boosting option_method :negative option_method :negative_boost end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/common.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/common.rb index c86261a5b..0e7957fc6 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/common.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/common.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which executes the search for low frequency terms first, and high frequency ("common") # terms second # @@ -57,7 +56,6 @@ class Common option_method :analyzer option_method :disable_coord end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/constant_score.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/constant_score.rb index 3f36e288a..31d1ddedb 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/constant_score.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/constant_score.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which wraps another query or filter and returns a constant score for matching documents # # @example @@ -76,16 +75,15 @@ def to_hash hash = super if @query _query = @query.respond_to?(:to_hash) ? @query.to_hash : @query - hash[self.name].update(query: _query) + hash[name].update(query: _query) end if @filter _filter = @filter.respond_to?(:to_hash) ? @filter.to_hash : @filter - hash[self.name].update(filter: _filter) + hash[name].update(filter: _filter) end hash end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/dis_max.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/dis_max.rb index d696bd550..e25952bfa 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/dis_max.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/dis_max.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which will score the documents based on the highest score of any individual specified query, # not by summing the scores (as eg. a `bool` query would) # @@ -54,7 +53,6 @@ class DisMax option_method :boost option_method :tie_breaker end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/exists.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/exists.rb index 27eb9aa3f..0eb8abdf4 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/exists.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/exists.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # Returns documents that have at least one non-null value in the field. # # @example Find documents with non-empty "name" property diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/filtered.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/filtered.rb index 81fa04bed..7ffef0d6c 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/filtered.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/filtered.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which allows to combine a query with a filter # # @note It's possible and common to define just the `filter` part of the search definition, @@ -87,16 +86,15 @@ def to_hash hash = super if @query _query = @query.respond_to?(:to_hash) ? @query.to_hash : @query - hash[self.name].update(query: _query) + hash[name].update(query: _query) end if @filter _filter = @filter.respond_to?(:to_hash) ? @filter.to_hash : @filter - hash[self.name].update(filter: _filter) + hash[name].update(filter: _filter) end hash end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/function_score.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/function_score.rb index 0c6be2ac1..bcaf2b2b4 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/function_score.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/function_score.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which allows to modify the score of documents matching the query, # either via built-in functions or a custom script # @@ -85,7 +84,7 @@ def filter(*args, &block) # # @return [Array] # - def functions(value=nil) + def functions(value = nil) if value @functions = value else @@ -97,9 +96,7 @@ def functions(value=nil) # # @return [Array] # - def functions=(value) - @functions = value - end + attr_writer :functions # Converts the query definition to a Hash # @@ -109,19 +106,16 @@ def to_hash hash = super if @query _query = @query.respond_to?(:to_hash) ? @query.to_hash : @query - hash[self.name].update(query: _query) + hash[name].update(query: _query) end if @filter _filter = @filter.respond_to?(:to_hash) ? @filter.to_hash : @filter - hash[self.name].update(filter: _filter) - end - unless @functions.empty? - hash[self.name].update(functions: @functions) + hash[name].update(filter: _filter) end + hash[name].update(functions: @functions) unless @functions.empty? hash end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/fuzzy.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/fuzzy.rb index b7fcbb573..712bce494 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/fuzzy.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/fuzzy.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which uses a Levenshtein distance on string fields and plus-minus margin on numerical # fields to match documents # @@ -64,7 +63,6 @@ class Fuzzy option_method :prefix_length option_method :max_expansions end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/fuzzy_like_this.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/fuzzy_like_this.rb index 3c6af658c..0de0aa83f 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/fuzzy_like_this.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/fuzzy_like_this.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents which are similar to the specified text # # @example @@ -56,7 +55,6 @@ class FuzzyLikeThis option_method :boost option_method :ignore_tf end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/fuzzy_like_this_field.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/fuzzy_like_this_field.rb index 4da7786cc..3b11b6935 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/fuzzy_like_this_field.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/fuzzy_like_this_field.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents which are similar to the specified text, # executed on a single field # @@ -55,7 +54,6 @@ class FuzzyLikeThisField option_method :boost option_method :ignore_tf end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/geo_shape.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/geo_shape.rb index caa00d1a1..07295b2e1 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/geo_shape.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/geo_shape.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents which fall into a specified geographical shape # # @example @@ -49,7 +48,6 @@ class GeoShape option_method :shape option_method :indexed_shape end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/has_child.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/has_child.rb index 1abe7ac09..4beddad23 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/has_child.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/has_child.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns parent documents for children documents matching a query # # @example Return articles where John has commented @@ -72,12 +71,11 @@ def to_hash hash = super if @query _query = @query.respond_to?(:to_hash) ? @query.to_hash : @query - hash[self.name].update(query: _query) + hash[name].update(query: _query) end hash end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/has_parent.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/has_parent.rb index 70e283a73..fd51346e9 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/has_parent.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/has_parent.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns children documents for parent documents matching a query # # @example Return comments for articles about Ruby @@ -72,12 +71,11 @@ def to_hash hash = super if @query _query = @query.respond_to?(:to_hash) ? @query.to_hash : @query - hash[self.name].update(query: _query) + hash[name].update(query: _query) end hash end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/ids.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/ids.rb index c6c67b937..f95be90c1 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/ids.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/ids.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents matching the specified IDs # # @example @@ -47,7 +46,6 @@ class Ids option_method :type option_method :values end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/indices.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/indices.rb index d7a1e3608..f3746ea82 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/indices.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/indices.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which executes a custom query only for documents in specified indices, # and optionally another query for documents in other indices # @@ -53,7 +52,6 @@ class Indices option_method :query option_method :no_match_query end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/match.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/match.rb index 5d984aaa0..c3de780b7 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/match.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/match.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A simple to use, yet sophisticated query which returns documents matching the specified terms, # taking into account field types, analyzers, etc. and allowing to search in phrase, prefix, fuzzy modes # @@ -62,7 +61,6 @@ class Match option_method :cutoff_frequency option_method :max_expansions end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/match_all.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/match_all.rb index 6f7e1098f..8dac83151 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/match_all.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/match_all.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which matches all documents # # @example @@ -45,7 +44,6 @@ class MatchAll option_method :boost end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/match_phrase.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/match_phrase.rb index b487a34e3..da76a219e 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/match_phrase.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/match_phrase.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query that analyzes the text and creates a phrase query out of the analyzed text # # @example @@ -51,7 +50,6 @@ class MatchPhrase option_method :boost option_method :slop end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/match_phrase_prefix.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/match_phrase_prefix.rb index fc3b17543..9b5e491c2 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/match_phrase_prefix.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/match_phrase_prefix.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # The same as match_phrase, except that it allows for prefix matches on the last term in the text # # @example @@ -50,7 +49,6 @@ class MatchPhrasePrefix option_method :boost option_method :max_expansions end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/more_like_this.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/more_like_this.rb index 0e94fa102..729a1cda7 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/more_like_this.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/more_like_this.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents which are similar to the specified text or documents # # @example Find documents similar to the provided text @@ -83,7 +82,6 @@ class MoreLikeThis option_method :boost option_method :analyzer end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/multi_match.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/multi_match.rb index cfc86f721..b6d292fa6 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/multi_match.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/multi_match.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which allows to use the `match` query on multiple fields # # @example @@ -64,7 +63,6 @@ class MultiMatch option_method :use_dis_max option_method :zero_terms_query end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/nested.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/nested.rb index 5c796aa5b..ac7fd1a2c 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/nested.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/nested.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns the root documents for nested documents matching the specified query # # @example Return articles where John has commented @@ -70,12 +69,11 @@ def to_hash hash = super if @query _query = @query.respond_to?(:to_hash) ? @query.to_hash : @query - hash[self.name].update(query: _query) + hash[name].update(query: _query) end hash end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/prefix.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/prefix.rb index b23fe0221..eaafc3128 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/prefix.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/prefix.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents matching a specified prefix # # @example @@ -49,7 +48,6 @@ class Prefix option_method :value option_method :boost end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/query_string.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/query_string.rb index a36518bf8..d987e3799 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/query_string.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/query_string.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents matching a specified expression in the Lucene Query String syntax # # @example @@ -70,7 +69,6 @@ class QueryString option_method :tie_breaker option_method :time_zone end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/range.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/range.rb index 311e86bcc..edb7585e4 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/range.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/range.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents matching the specified range # # @example Find documents within a numeric range @@ -66,7 +65,6 @@ class Range option_method :time_zone option_method :format end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/regexp.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/regexp.rb index e87ce03c1..9e7a6a893 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/regexp.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/regexp.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which matches documents matching a regular expression # # @example @@ -50,7 +49,6 @@ class Regexp option_method :boost option_method :flags end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/simple_query_string.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/simple_query_string.rb index c0be9c3f7..e1c3e1a49 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/simple_query_string.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/simple_query_string.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents matching a simplified query string syntax # # @example @@ -59,7 +58,6 @@ class SimpleQueryString option_method :quote_field_suffix option_method :all_fields end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/span_first.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/span_first.rb index 5ddcf323d..fb8d28505 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/span_first.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/span_first.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents having spans in the beginning of the field # # @example @@ -47,7 +46,6 @@ class SpanFirst option_method :match end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/span_multi.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/span_multi.rb index 463ed3690..5451db3d2 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/span_multi.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/span_multi.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents matching a multi-term query as a span query # # @example @@ -47,7 +46,6 @@ class SpanMulti option_method :match end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/span_near.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/span_near.rb index dc251cdc3..39619eb40 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/span_near.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/span_near.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents matching spans near each other # # @example @@ -51,7 +50,6 @@ class SpanNear option_method :in_order option_method :collect_payloads end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/span_not.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/span_not.rb index 7014c0162..6382408aa 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/span_not.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/span_not.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which discards matching documents which overlap with another query # # @example @@ -52,7 +51,6 @@ class SpanNot option_method :post option_method :dist end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/span_or.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/span_or.rb index 654abcda1..b7e3a7a65 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/span_or.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/span_or.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents matching the union of provided queries # # @example @@ -47,7 +46,6 @@ class SpanOr option_method :clauses end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/span_term.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/span_term.rb index 8355eecde..89e5f9dc5 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/span_term.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/span_term.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents having a span containing a term # # @example @@ -45,7 +44,6 @@ module Queries class SpanTerm include BaseComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/template.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/template.rb index 3fdcce265..432d72397 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/template.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/template.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which allows to use Mustache templates for query definitions # # @example @@ -50,7 +49,6 @@ class Template option_method :query option_method :params end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/term.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/term.rb index 957ae476b..20a9e4573 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/term.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/term.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents matching the specified term # # @note The specified term is *not analyzed* (lowercased, stemmed, etc) @@ -45,7 +44,6 @@ module Queries class Term include BaseComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/terms.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/terms.rb index 3cb37165c..2d744738b 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/terms.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/terms.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents matching the specified terms # # @note The specified terms are *not analyzed* (lowercased, stemmed, etc) @@ -46,7 +45,6 @@ module Queries class Terms include BaseComponent end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/top_children.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/top_children.rb index 9f8da574f..c07fe7a68 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/top_children.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/top_children.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A filter which returns parent documents for children documents matching a query # # @example Return articles with comments mentioning 'twitter', summing the score @@ -72,12 +71,11 @@ def to_hash hash = super if @query _query = @query.respond_to?(:to_hash) ? @query.to_hash : @query - hash[self.name].update(query: _query) + hash[name].update(query: _query) end hash end end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/queries/wildcard.rb b/opensearch-dsl/lib/opensearch/dsl/search/queries/wildcard.rb index 72560d8c1..7d57bb90a 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/queries/wildcard.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/queries/wildcard.rb @@ -28,7 +28,6 @@ module OpenSearch module DSL module Search module Queries - # A query which returns documents matching a wildcard expression # # @note The expression is *not analyzed* (lowercased, stemmed, etc) @@ -49,7 +48,6 @@ class Wildcard option_method :value option_method :boost end - end end end diff --git a/opensearch-dsl/lib/opensearch/dsl/search/query.rb b/opensearch-dsl/lib/opensearch/dsl/search/query.rb index 70ab069a3..91ae90517 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/query.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/query.rb @@ -27,16 +27,15 @@ module OpenSearch module DSL module Search - # Contains the classes for OpenSearch queries # - module Queries;end + module Queries; end # Wraps the `query` part of a search definition # # class Query - def initialize(*args, &block) + def initialize(*_args, &block) @block = block end @@ -47,7 +46,7 @@ def initialize(*args, &block) def method_missing(name, *args, &block) klass = Utils.__camelize(name) if Queries.const_defined? klass - @value = Queries.const_get(klass).new *args, &block + @value = Queries.const_get(klass).new(*args, &block) else raise NoMethodError, "undefined method '#{name}' for #{self}" end @@ -58,7 +57,9 @@ def method_missing(name, *args, &block) # @return [self] # def call - @block.arity < 1 ? self.instance_eval(&@block) : @block.call(self) if @block + if @block + @block.arity < 1 ? instance_eval(&@block) : @block.call(self) + end self end @@ -66,7 +67,7 @@ def call # # @return [Hash] # - def to_hash(options={}) + def to_hash(_options = {}) call if @value @value.to_hash diff --git a/opensearch-dsl/lib/opensearch/dsl/search/sort.rb b/opensearch-dsl/lib/opensearch/dsl/search/sort.rb index e348b2049..c95ddb19b 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/sort.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/sort.rb @@ -27,7 +27,6 @@ module OpenSearch module DSL module Search - # Wraps the `sort` part of a search definition # # @@ -50,8 +49,8 @@ def initialize(*args, &block) # end # end # - def by(name, direction=nil) - @value << ( direction ? { name => direction } : name ) + def by(name, direction = nil) + @value << (direction ? { name => direction } : name) self end @@ -63,8 +62,8 @@ def to_hash if @block call unless @block_called @block_called = true - else - @value << @args if @args && !@args.empty? && ! @value.include?(@args) + elsif @args && !@args.empty? && !@value.include?(@args) + @value << @args end @hash = @value.flatten diff --git a/opensearch-dsl/lib/opensearch/dsl/search/suggest.rb b/opensearch-dsl/lib/opensearch/dsl/search/suggest.rb index b2a2ffbe9..a3bf0c9ed 100644 --- a/opensearch-dsl/lib/opensearch/dsl/search/suggest.rb +++ b/opensearch-dsl/lib/opensearch/dsl/search/suggest.rb @@ -27,14 +27,13 @@ module OpenSearch module DSL module Search - # Wraps the `suggest` part of a search definition # # class Suggest include BaseComponent - def initialize(key, options={}, &block) + def initialize(key, options = {}, &block) @key = key @options = options @block = block diff --git a/opensearch-dsl/lib/opensearch/dsl/utils.rb b/opensearch-dsl/lib/opensearch/dsl/utils.rb index fd377f589..a9f5c9d50 100644 --- a/opensearch-dsl/lib/opensearch/dsl/utils.rb +++ b/opensearch-dsl/lib/opensearch/dsl/utils.rb @@ -26,11 +26,9 @@ module OpenSearch module DSL - # Generic utility methods # module Utils - # Camelize an underscored string # # A lightweight version of ActiveSupport's `camelize` diff --git a/opensearch-dsl/lib/opensearch/dsl/version.rb b/opensearch-dsl/lib/opensearch/dsl/version.rb index 965dc1b2f..26f4479dd 100644 --- a/opensearch-dsl/lib/opensearch/dsl/version.rb +++ b/opensearch-dsl/lib/opensearch/dsl/version.rb @@ -26,6 +26,6 @@ module OpenSearch module DSL - VERSION = "0.2.1" + VERSION = '0.2.1' end end diff --git a/opensearch-dsl/opensearch-dsl.gemspec b/opensearch-dsl/opensearch-dsl.gemspec index 660f2b855..fb6dc3cda 100644 --- a/opensearch-dsl/opensearch-dsl.gemspec +++ b/opensearch-dsl/opensearch-dsl.gemspec @@ -25,55 +25,55 @@ # under the License. # coding: utf-8 -lib = File.expand_path('../lib', __FILE__) + +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'opensearch/dsl/version' -signing_key_path = File.expand_path("../gem-private_key.pem") +signing_key_path = File.expand_path('../gem-private_key.pem') Gem::Specification.new do |s| s.name = 'opensearch-dsl' s.version = OpenSearch::DSL::VERSION - s.authors = ['Jayesh Hathila', 'Vamshi Vijay Nakkirtha', 'Vijayan Balasubramanian' , 'Yuvraj Jaiswal'] + s.authors = ['Jayesh Hathila', 'Vamshi Vijay Nakkirtha', 'Vijayan Balasubramanian', 'Yuvraj Jaiswal'] s.email = ['jayehh@amazon.com', 'vamshin@amazon.com', 'balasvij@amazon.com', 'jaiyuvra@amazon.com'] - s.description = %q{A Ruby DSL builder for OpenSearch} + s.description = 'A Ruby DSL builder for OpenSearch' s.summary = s.description s.homepage = 'https://opensearch.org/docs/latest/' s.license = 'Apache-2.0' s.metadata = { 'homepage_uri' => 'https://opensearch.org/docs/latest/', 'source_code_uri' => 'https://github.com/opensearch-project/opensearch-ruby/tree/main/opensearch-dsl', - 'bug_tracker_uri' => 'https://github.com/opensearch-project/opensearch-ruby/issues' + 'bug_tracker_uri' => 'https://github.com/opensearch-project/opensearch-ruby/issues', + 'rubygems_mfa_required' => 'true' } s.files = `git ls-files`.split($/) s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) } s.test_files = s.files.grep(%r{^(test|spec|features)/}) - if $PROGRAM_NAME.end_with?("gem") && ARGV == ["build", __FILE__] && File.exist?(signing_key_path) + if $PROGRAM_NAME.end_with?('gem') && ARGV == ['build', __FILE__] && File.exist?(signing_key_path) s.signing_key = signing_key_path s.cert_chain = ['../certs/opensearch-rubygems.pem'] end s.require_paths = ['lib'] - s.extra_rdoc_files = [ 'README.md', 'LICENSE' ] - s.rdoc_options = [ '--charset=UTF-8' ] + s.extra_rdoc_files = ['README.md', 'LICENSE'] + s.rdoc_options = ['--charset=UTF-8'] s.required_ruby_version = '>= 2.4' s.add_development_dependency 'bundler' - s.add_development_dependency 'rake', '~> 13' - s.add_development_dependency 'opensearch-ruby', '~> 2' s.add_development_dependency 'cane' s.add_development_dependency 'minitest', '~> 5' s.add_development_dependency 'minitest-reporters', '~> 1' s.add_development_dependency 'mocha', '~> 1' + s.add_development_dependency 'opensearch-ruby', '~> 2' s.add_development_dependency 'pry' + s.add_development_dependency 'rake', '~> 13' s.add_development_dependency 'shoulda-context' s.add_development_dependency 'simplecov', '~> 0.17', '< 0.18' s.add_development_dependency 'yard' - if defined?(RUBY_VERSION) && RUBY_VERSION > '2.2' - s.add_development_dependency 'test-unit', '~> 2' - end + s.add_development_dependency 'test-unit', '~> 2' if defined?(RUBY_VERSION) && RUBY_VERSION > '2.2' end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/avg_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/avg_spec.rb index 97eb6477b..916982236 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/avg_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/avg_spec.rb @@ -27,20 +27,17 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Avg do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(avg: {}) end end - context '#initialize' do - + describe '#initialize' do let(:search) do described_class.new(foo: 'bar') end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/cardinality_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/cardinality_spec.rb index ca2ba8413..500114b88 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/cardinality_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/cardinality_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Cardinality do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(cardinality: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('bar') end @@ -57,7 +53,6 @@ end describe '#precision_threshold' do - before do search.precision_threshold('bar') end @@ -68,7 +63,6 @@ end describe '#rehash' do - before do search.rehash('skip') end @@ -79,7 +73,6 @@ end describe '#script' do - before do search.script('bar') end @@ -90,7 +83,6 @@ end describe '#params' do - before do search.params('bar') end @@ -102,9 +94,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do field 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/children_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/children_spec.rb index 108ca17e4..e5d36b73e 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/children_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/children_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Children do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(children: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#type' do - before do search.type('bar') end @@ -58,9 +54,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do type 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/composite_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/composite_spec.rb index 06aa4ac9e..ffc8783a4 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/composite_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/composite_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Composite do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(composite: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#size' do - before do search.size(2_000) end @@ -57,7 +53,6 @@ end describe '#sources' do - before do search.sources('bar') end @@ -91,9 +86,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do size 2_000 diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/date_histogram_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/date_histogram_spec.rb index 3db2e544c..89b500bb2 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/date_histogram_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/date_histogram_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::DateHistogram do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(date_histogram: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('bar') end @@ -57,7 +53,6 @@ end describe '#interval' do - before do search.interval('bar') end @@ -68,7 +63,6 @@ end describe '#pre_zone' do - before do search.pre_zone('bar') end @@ -79,7 +73,6 @@ end describe '#post_zone' do - before do search.post_zone('bar') end @@ -90,7 +83,6 @@ end describe '#time_zone' do - before do search.time_zone('bar') end @@ -101,7 +93,6 @@ end describe '#pre_zone_adjust_large_interval' do - before do search.pre_zone_adjust_large_interval('bar') end @@ -112,7 +103,6 @@ end describe '#pre_offest' do - before do search.pre_offset('bar') end @@ -123,7 +113,6 @@ end describe '#post_offset' do - before do search.post_offset('bar') end @@ -134,7 +123,6 @@ end describe '#format' do - before do search.format('bar') end @@ -145,7 +133,6 @@ end describe '#min_doc_count' do - before do search.min_doc_count('bar') end @@ -156,7 +143,6 @@ end describe '#extended_bounds' do - before do search.extended_bounds('bar') end @@ -167,7 +153,6 @@ end describe '#order' do - before do search.order('bar') end @@ -179,9 +164,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/date_range_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/date_range_spec.rb index 71284de65..ab4964785 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/date_range_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/date_range_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::DateRange do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(date_range: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('bar') end @@ -57,7 +53,6 @@ end describe '#format' do - before do search.format('bar') end @@ -68,7 +63,6 @@ end describe '#ranges' do - before do search.ranges('bar') end @@ -80,18 +74,16 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' - ranges [ {to: 'foo'}, {from: 'bar'} ] + ranges [{ to: 'foo' }, { from: 'bar' }] end end it 'executes the block' do - expect(search.to_hash).to eq(date_range: { field: 'bar', ranges: [ {to: 'foo'}, {from: 'bar'} ] }) + expect(search.to_hash).to eq(date_range: { field: 'bar', ranges: [{ to: 'foo' }, { from: 'bar' }] }) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/extended_stats_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/extended_stats_spec.rb index 46a9e9253..db42475ef 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/extended_stats_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/extended_stats_spec.rb @@ -27,20 +27,17 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::ExtendedStats do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(extended_stats: {}) end end - context '#initialize' do - + describe '#initialize' do let(:search) do described_class.new(foo: 'bar') end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/filter_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/filter_spec.rb index 9b40f7e78..fb6c8e745 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/filter_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/filter_spec.rb @@ -27,20 +27,17 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Filter do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(filter: {}) end end context 'when another aggregation is nested' do - let(:search) do described_class.new(terms: { foo: 'bar' }) do aggregation :sum_clicks do diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/filters_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/filters_spec.rb index 3cb8f0fe5..3bf261747 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/filters_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/filters_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Filters do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(filters: {}) end end context 'when options methods are called' do - let(:search) do described_class.new end describe '#filters' do - before do search.filters(foo: 'bar') end @@ -57,8 +53,7 @@ end end - context '#initialize' do - + describe '#initialize' do let(:search) do described_class.new(foo: 'bar') end @@ -68,7 +63,6 @@ end context 'when filters are passed' do - let(:search) do described_class.new(filters: { foo: 'bar' }) end @@ -80,7 +74,6 @@ end context 'when another aggregation is nested' do - let(:search) do described_class.new do filters foo: { terms: { foo: 'bar' } } diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/geo_bounds_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/geo_bounds_spec.rb index 2f1c780d3..19a93da05 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/geo_bounds_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/geo_bounds_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::GeoBounds do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(geo_bounds: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('bar') end @@ -57,7 +53,6 @@ end describe '#wrap_longitude' do - before do search.wrap_longitude('bar') end @@ -69,9 +64,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/geo_distance_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/geo_distance_spec.rb index 25da2d8eb..5133f0ce9 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/geo_distance_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/geo_distance_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::GeoDistance do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(geo_distance: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('bar') end @@ -57,7 +53,6 @@ end describe '#origin' do - before do search.origin('bar') end @@ -68,7 +63,6 @@ end describe '#ranges' do - before do search.ranges('bar') end @@ -79,7 +73,6 @@ end describe '#unit' do - before do search.unit('bar') end @@ -90,7 +83,6 @@ end describe '#distance_type' do - before do search.distance_type('bar') end @@ -102,20 +94,18 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' origin lat: 50, lon: 5 - ranges [ { to: 50 }, { from: 50, to: 100 }, { from: 100 } ] + ranges [{ to: 50 }, { from: 50, to: 100 }, { from: 100 }] end end it 'executes the block' do expect(search.to_hash).to eq(geo_distance: { field: 'bar', origin: { lat: 50, lon: 5 }, - ranges: [ { to: 50 }, { from: 50, to: 100 }, { from: 100 } ] }) + ranges: [{ to: 50 }, { from: 50, to: 100 }, { from: 100 }] }) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/geo_grid_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/geo_grid_spec.rb index 3cd5715e3..24437e4cc 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/geo_grid_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/geo_grid_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::GeohashGrid do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(geohash_grid: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('bar') end @@ -57,7 +53,6 @@ end describe '#precision' do - before do search.precision('bar') end @@ -68,7 +63,6 @@ end describe '#size' do - before do search.size('bar') end @@ -79,7 +73,6 @@ end describe '#shard_size' do - before do search.shard_size('bar') end @@ -91,9 +84,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/global_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/global_spec.rb index 6847b37fb..566de2e46 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/global_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/global_spec.rb @@ -27,22 +27,18 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Global do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(global: {}) end end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do end @@ -54,17 +50,16 @@ end context 'when another aggregation is nested' do - let(:search) do described_class.new do aggregation :foo do - terms field: "bar" + terms field: 'bar' end end end it 'nests the aggregation in the hash' do - expect(search.to_hash).to eq(aggregations: { foo: { terms: { field: "bar" } } }, global: {}) + expect(search.to_hash).to eq(aggregations: { foo: { terms: { field: 'bar' } } }, global: {}) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/historgram_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/historgram_spec.rb index b1524eb14..52efe31ee 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/historgram_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/historgram_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Histogram do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(histogram: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('bar') end @@ -57,7 +53,6 @@ end describe '#interval' do - before do search.interval('bar') end @@ -68,7 +63,6 @@ end describe '#min_doc_count' do - before do search.min_doc_count('bar') end @@ -79,7 +73,6 @@ end describe '#extended_bounds' do - before do search.extended_bounds('bar') end @@ -90,7 +83,6 @@ end describe '#order' do - before do search.order('bar') end @@ -101,7 +93,6 @@ end describe '#keyed' do - before do search.keyed('bar') end @@ -113,9 +104,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/ip_range_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/ip_range_spec.rb index 2d60cdc55..6da1556f9 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/ip_range_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/ip_range_spec.rb @@ -27,13 +27,11 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::IpRange do - let(:search) do described_class.new end - context '#initialize' do - + describe '#initialize' do let(:search) do described_class.new(foo: 'bar') end @@ -43,25 +41,22 @@ end context 'when args are passed' do - let(:search) do - described_class.new(field: 'test', ranges: [ {to: 'foo'}, {from: 'bar'} ]) + described_class.new(field: 'test', ranges: [{ to: 'foo' }, { from: 'bar' }]) end it 'defines filters' do - expect(search.to_hash).to eq(ip_range: { field: 'test', ranges: [ {to: 'foo'}, {from: 'bar'} ] }) + expect(search.to_hash).to eq(ip_range: { field: 'test', ranges: [{ to: 'foo' }, { from: 'bar' }] }) end end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('bar') end @@ -72,7 +67,6 @@ end describe '#ranges' do - before do search.ranges('bar') end @@ -84,18 +78,16 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' - ranges [ {to: 'foo'}, {from: 'bar'} ] + ranges [{ to: 'foo' }, { from: 'bar' }] end end it 'executes the block' do - expect(search.to_hash).to eq(ip_range: { field: 'bar', ranges: [ {to: 'foo'}, {from: 'bar'} ] }) + expect(search.to_hash).to eq(ip_range: { field: 'bar', ranges: [{ to: 'foo' }, { from: 'bar' }] }) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/max_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/max_spec.rb index 248b56483..feaa22bda 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/max_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/max_spec.rb @@ -27,20 +27,17 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Max do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(max: {}) end end - context '#initialize' do - + describe '#initialize' do let(:search) do described_class.new(foo: 'bar') end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/min_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/min_spec.rb index 8822bad31..9ff7d8a01 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/min_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/min_spec.rb @@ -27,20 +27,17 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Min do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(min: {}) end end - context '#initialize' do - + describe '#initialize' do let(:search) do described_class.new(foo: 'bar') end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/missing_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/missing_spec.rb index 3436d2f61..a338e0046 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/missing_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/missing_spec.rb @@ -27,13 +27,11 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Missing do - let(:search) do described_class.new end - context '#initialize' do - + describe '#initialize' do let(:search) do described_class.new(foo: 'bar') end @@ -43,7 +41,6 @@ end context 'when args are passed' do - let(:search) do described_class.new(field: 'test') end @@ -55,13 +52,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('bar') end @@ -73,9 +68,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/nested_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/nested_spec.rb index 95fff4dfc..3a23a0586 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/nested_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/nested_spec.rb @@ -27,13 +27,11 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Nested do - let(:search) do described_class.new end - context '#initialize' do - + describe '#initialize' do let(:search) do described_class.new(path: 'bar') end @@ -44,13 +42,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#path' do - before do search.path('bar') end @@ -62,9 +58,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do path 'bar' @@ -77,7 +71,6 @@ end context 'when another aggregation is nested' do - let(:search) do described_class.new do path 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/percentile_ranks_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/percentile_ranks_spec.rb index 34e04a089..7246999c4 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/percentile_ranks_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/percentile_ranks_spec.rb @@ -27,13 +27,11 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::PercentileRanks do - let(:search) do described_class.new end - context '#initialize' do - + describe '#initialize' do let(:search) do described_class.new(foo: 'bar') end @@ -43,7 +41,6 @@ end context 'when args are passed' do - let(:search) do described_class.new(field: 'test') end @@ -55,13 +52,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('bar') end @@ -72,7 +67,6 @@ end describe '#values' do - before do search.values('bar') end @@ -83,7 +77,6 @@ end describe '#script' do - before do search.script('bar') end @@ -94,7 +87,6 @@ end describe '#params' do - before do search.params('bar') end @@ -105,7 +97,6 @@ end describe '#compression' do - before do search.compression('bar') end @@ -117,9 +108,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/percentiles_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/percentiles_spec.rb index a014d66f4..44d9cf502 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/percentiles_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/percentiles_spec.rb @@ -27,13 +27,11 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Percentiles do - let(:search) do described_class.new end - context '#initialize' do - + describe '#initialize' do let(:search) do described_class.new(foo: 'bar') end @@ -43,7 +41,6 @@ end context 'when args are passed' do - let(:search) do described_class.new(field: 'test') end @@ -55,13 +52,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('bar') end @@ -72,7 +67,6 @@ end describe '#percents' do - before do search.percents('bar') end @@ -83,7 +77,6 @@ end describe '#script' do - before do search.script('bar') end @@ -94,7 +87,6 @@ end describe '#params' do - before do search.params('bar') end @@ -105,7 +97,6 @@ end describe '#compression' do - before do search.compression('bar') end @@ -117,9 +108,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/avg_bucket_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/avg_bucket_spec.rb index 0f0839343..2582b610e 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/avg_bucket_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/avg_bucket_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::AvgBucket do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(avg_bucket: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#buckets_path' do - before do search.buckets_path('bar') end @@ -57,7 +53,6 @@ end describe '#gap_policy' do - before do search.gap_policy('skip') end @@ -68,7 +63,6 @@ end describe '#format' do - before do search.format('bar') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do format 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/bucket_script_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/bucket_script_spec.rb index e51a4b683..4666a5c52 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/bucket_script_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/bucket_script_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::BucketScript do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(bucket_script: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#buckets_path' do - before do search.buckets_path('bar') end @@ -57,7 +53,6 @@ end describe '#script' do - before do search.script('bar') end @@ -68,7 +63,6 @@ end describe '#gap_policy' do - before do search.gap_policy('skip') end @@ -79,7 +73,6 @@ end describe '#format' do - before do search.format('bar') end @@ -91,9 +84,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do format 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/bucket_selector_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/bucket_selector_spec.rb index 2ef18fdd5..3826a5839 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/bucket_selector_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/bucket_selector_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::BucketSelector do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(bucket_selector: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#buckets_path' do - before do search.buckets_path('bar') end @@ -57,7 +53,6 @@ end describe '#script' do - before do search.script('bar') end @@ -68,7 +63,6 @@ end describe '#gap_policy' do - before do search.gap_policy('skip') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do gap_policy 'skip' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/bucket_sort_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/bucket_sort_spec.rb index 26c94f351..9aac240e5 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/bucket_sort_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/bucket_sort_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::BucketSort do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(bucket_sort: {}) end end context 'when options methods are called' do - let(:search) do described_class.new end describe '#sort' do - before do search.sort do by :category, order: 'desc' @@ -59,7 +55,6 @@ end describe '#from' do - before do search.from(5) end @@ -70,7 +65,6 @@ end describe '#size' do - before do search.size(10) end @@ -81,7 +75,6 @@ end describe '#gap_policy' do - before do search.gap_policy('insert_zero') end @@ -93,9 +86,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do sort do diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/cumulative_sum_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/cumulative_sum_spec.rb index e0e7b1a81..14abd12bf 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/cumulative_sum_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/cumulative_sum_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::CumulativeSum do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(cumulative_sum: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#buckets_path' do - before do search.buckets_path('bar') end @@ -57,7 +53,6 @@ end describe '#script' do - before do search.format('bar') end @@ -69,9 +64,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do format 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/derivative_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/derivative_spec.rb index bab37c2fb..bb0c069ae 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/derivative_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/derivative_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Derivative do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(derivative: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#buckets_path' do - before do search.buckets_path('bar') end @@ -57,7 +53,6 @@ end describe '#gap_policy' do - before do search.gap_policy('bar') end @@ -68,7 +63,6 @@ end describe '#script' do - before do search.format('bar') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do format 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/extended_stats_bucket_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/extended_stats_bucket_spec.rb index 2e9be973f..a47a6530f 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/extended_stats_bucket_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/extended_stats_bucket_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::ExtendedStatsBucket do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(extended_stats_bucket: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#buckets_path' do - before do search.buckets_path('bar') end @@ -57,7 +53,6 @@ end describe '#gap_policy' do - before do search.gap_policy('bar') end @@ -68,7 +63,6 @@ end describe '#format' do - before do search.format('bar') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do format 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/max_bucket_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/max_bucket_spec.rb index 6fea89ec7..019a3f23e 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/max_bucket_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/max_bucket_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::MaxBucket do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(max_bucket: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#buckets_path' do - before do search.buckets_path('bar') end @@ -57,7 +53,6 @@ end describe '#gap_policy' do - before do search.gap_policy('bar') end @@ -68,7 +63,6 @@ end describe '#format' do - before do search.format('bar') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do format 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/min_bucket_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/min_bucket_spec.rb index 7f0a036fd..f29c65e73 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/min_bucket_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/min_bucket_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::MinBucket do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(min_bucket: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#buckets_path' do - before do search.buckets_path('bar') end @@ -57,7 +53,6 @@ end describe '#gap_policy' do - before do search.gap_policy('bar') end @@ -68,7 +63,6 @@ end describe '#format' do - before do search.format('bar') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do format 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/moving_avg_test_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/moving_avg_test_spec.rb index 76e8d6a6e..277b90113 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/moving_avg_test_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/moving_avg_test_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::MovingAvg do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(moving_avg: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#buckets_path' do - before do search.buckets_path('bar') end @@ -57,7 +53,6 @@ end describe '#gap_policy' do - before do search.gap_policy('bar') end @@ -68,18 +63,16 @@ end describe '#minimize' do - before do search.minimize(false) end it 'applies the option' do - expect(search.to_hash[:moving_avg][:foo][:minimize]).to eq(false) + expect(search.to_hash[:moving_avg][:foo][:minimize]).to be(false) end end describe '#model' do - before do search.model('simple') end @@ -90,7 +83,6 @@ end describe '#settings' do - before do search.settings(period: 7) end @@ -101,7 +93,6 @@ end describe '#window' do - before do search.window(5) end @@ -112,7 +103,6 @@ end describe '#format' do - before do search.format('bar') end @@ -124,9 +114,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do format 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/percentiles_bucket_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/percentiles_bucket_spec.rb index 57ace311e..1b79f28da 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/percentiles_bucket_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/percentiles_bucket_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::PercentilesBucket do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(percentiles_bucket: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#buckets_path' do - before do search.buckets_path('bar') end @@ -57,7 +53,6 @@ end describe '#gap_policy' do - before do search.gap_policy('bar') end @@ -68,7 +63,6 @@ end describe '#format' do - before do search.format('bar') end @@ -79,21 +73,18 @@ end describe '#percents' do - before do - search.percents([ 1, 5, 25, 50, 75, 95, 99 ]) + search.percents([1, 5, 25, 50, 75, 95, 99]) end it 'applies the option' do - expect(search.to_hash[:percentiles_bucket][:foo][:percents]).to eq([ 1, 5, 25, 50, 75, 95, 99 ]) + expect(search.to_hash[:percentiles_bucket][:foo][:percents]).to eq([1, 5, 25, 50, 75, 95, 99]) end end end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do format 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/serial_diff_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/serial_diff_spec.rb index 6d2d00aa5..71c28037c 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/serial_diff_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/serial_diff_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::SerialDiff do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(serial_diff: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#buckets_path' do - before do search.buckets_path('bar') end @@ -57,7 +53,6 @@ end describe '#lag' do - before do search.lag(1) end @@ -68,7 +63,6 @@ end describe '#gap_policy' do - before do search.gap_policy('bar') end @@ -79,7 +73,6 @@ end describe '#format' do - before do search.format('bar') end @@ -91,9 +84,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do format 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/stats_bucket_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/stats_bucket_spec.rb index 71a0cce98..6758ab6d5 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/stats_bucket_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/stats_bucket_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::StatsBucket do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(stats_bucket: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#buckets_path' do - before do search.buckets_path('bar') end @@ -57,7 +53,6 @@ end describe '#gap_policy' do - before do search.gap_policy('bar') end @@ -68,7 +63,6 @@ end describe '#format' do - before do search.format('bar') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do format 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/sum_bucket_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/sum_bucket_spec.rb index 5e1fe5178..bb9466cb7 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/sum_bucket_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/pipeline/sum_bucket_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::SumBucket do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(sum_bucket: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#buckets_path' do - before do search.buckets_path('bar') end @@ -57,7 +53,6 @@ end describe '#gap_policy' do - before do search.gap_policy('bar') end @@ -68,7 +63,6 @@ end describe '#format' do - before do search.format('bar') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do format 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/range_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/range_spec.rb index 987f22b98..5384082ea 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/range_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/range_spec.rb @@ -27,30 +27,26 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Range do - let(:search) do described_class.new end - context '#initialize' do - + describe '#initialize' do let(:search) do - described_class.new(field: 'test', ranges: [ { to: 50 } ]) + described_class.new(field: 'test', ranges: [{ to: 50 }]) end it 'takes a hash' do - expect(search.to_hash).to eq(range: { field: "test", ranges: [ {to: 50} ] }) + expect(search.to_hash).to eq(range: { field: 'test', ranges: [{ to: 50 }] }) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('foo') end @@ -61,7 +57,6 @@ end describe '#script' do - before do search.script('bar*2') end @@ -73,11 +68,8 @@ end describe '#initialize' do - context 'when a block is provided' do - context 'when keyed ranges are provided' do - let(:search) do described_class.new(field: 'test') do key 'foo', to: 10 @@ -86,13 +78,12 @@ end it 'sets the values' do - expect(search.to_hash).to eq(range: { field: "test", keyed: true, - ranges: [ {to: 10, key: 'foo'}, { from: 10, to: 20, key: 'bar'}]}) + expect(search.to_hash).to eq(range: { field: 'test', keyed: true, + ranges: [{ to: 10, key: 'foo' }, { from: 10, to: 20, key: 'bar' }] }) end end context 'when keyed is set to false explicitly' do - let(:search) do described_class.new do keyed false @@ -103,13 +94,12 @@ end it 'sets the value' do - expect(search.to_hash).to eq(range: { field: "test", keyed: false, - ranges: [ {to: 10, key: 'foo'}, { from: 10, to: 20, key: 'bar'}]}) + expect(search.to_hash).to eq(range: { field: 'test', keyed: false, + ranges: [{ to: 10, key: 'foo' }, { from: 10, to: 20, key: 'bar' }] }) end end context 'when field is defined' do - let(:search) do described_class.new do field 'test' @@ -119,8 +109,8 @@ end it 'sets the value' do - expect(search.to_hash).to eq(range: { field: "test", keyed: true, - ranges: [ {to: 10, key: 'foo'}, { from: 10, to: 20, key: 'bar'}]}) + expect(search.to_hash).to eq(range: { field: 'test', keyed: true, + ranges: [{ to: 10, key: 'foo' }, { from: 10, to: 20, key: 'bar' }] }) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/reverse_nested_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/reverse_nested_spec.rb index ba73c1f58..6875b94c5 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/reverse_nested_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/reverse_nested_spec.rb @@ -27,13 +27,11 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::ReverseNested do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(reverse_nested: {}) end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/scripted_metric_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/scripted_metric_spec.rb index d042d10a7..85b415c28 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/scripted_metric_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/scripted_metric_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::ScriptedMetric do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(scripted_metric: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#init_script' do - before do search.init_script('bar') end @@ -57,7 +53,6 @@ end describe '#map_script' do - before do search.map_script('bar') end @@ -68,7 +63,6 @@ end describe '#combine_script' do - before do search.combine_script('bar') end @@ -79,7 +73,6 @@ end describe '#reduce_script' do - before do search.reduce_script('bar') end @@ -90,7 +83,6 @@ end describe '#params' do - before do search.params('bar') end @@ -101,7 +93,6 @@ end describe '#lang' do - before do search.lang('bar') end @@ -113,9 +104,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do init_script 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/significant_terms_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/significant_terms_spec.rb index 49f20d250..d0e8efd51 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/significant_terms_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/significant_terms_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::SignificantTerms do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(significant_terms: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('bar') end @@ -57,7 +53,6 @@ end describe '#size' do - before do search.size('bar') end @@ -68,7 +63,6 @@ end describe '#shard_size' do - before do search.shard_size('bar') end @@ -79,7 +73,6 @@ end describe '#min_doc_count' do - before do search.min_doc_count('bar') end @@ -90,7 +83,6 @@ end describe '#shard_min_doc_count' do - before do search.shard_min_doc_count('bar') end @@ -101,7 +93,6 @@ end describe '#include' do - before do search.include('bar') end @@ -112,7 +103,6 @@ end describe '#exclude' do - before do search.exclude('bar') end @@ -123,7 +113,6 @@ end describe '#background_filter' do - before do search.background_filter('bar') end @@ -134,7 +123,6 @@ end describe '#mutual_information' do - before do search.mutual_information('bar') end @@ -145,7 +133,6 @@ end describe '#chi_square' do - before do search.chi_square('bar') end @@ -156,7 +143,6 @@ end describe '#gnd' do - before do search.gnd('bar') end @@ -168,9 +154,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/stats_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/stats_spec.rb index da65df037..22cec7a20 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/stats_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/stats_spec.rb @@ -27,20 +27,17 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Stats do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(stats: {}) end end - context '#initialize' do - + describe '#initialize' do let(:search) do described_class.new(foo: 'bar') end @@ -50,7 +47,6 @@ end context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/sum_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/sum_spec.rb index 30f391365..9f517b38e 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/sum_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/sum_spec.rb @@ -27,20 +27,17 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Sum do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(sum: {}) end end - context '#initialize' do - + describe '#initialize' do let(:search) do described_class.new(foo: 'bar') end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/terms_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/terms_spec.rb index 004697692..a815ab023 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/terms_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/terms_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::Terms do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(terms: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('bar') end @@ -57,7 +53,6 @@ end describe '#size' do - before do search.size('bar') end @@ -68,7 +63,6 @@ end describe '#shard_size' do - before do search.shard_size('bar') end @@ -79,7 +73,6 @@ end describe '#order' do - before do search.shard_size('bar') end @@ -90,7 +83,6 @@ end describe '#min_doc_count' do - before do search.min_doc_count('bar') end @@ -101,7 +93,6 @@ end describe '#shard_min_doc_count' do - before do search.shard_min_doc_count('bar') end @@ -112,7 +103,6 @@ end describe '#include' do - before do search.include('bar') end @@ -123,7 +113,6 @@ end describe '#exclude' do - before do search.exclude('bar') end @@ -134,7 +123,6 @@ end describe '#script' do - before do search.script('bar') end @@ -146,9 +134,7 @@ end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do described_class.new(field: 'test') end @@ -159,7 +145,6 @@ end context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/top_hits_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/top_hits_spec.rb index 2e54680cc..c1e63ca4e 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/top_hits_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/top_hits_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::TopHits do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(top_hits: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#from' do - before do search.from('bar') end @@ -57,7 +53,6 @@ end describe '#size' do - before do search.size('bar') end @@ -68,7 +63,6 @@ end describe '#sort' do - before do search.sort('bar') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do from 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/value_count_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/value_count_spec.rb index 44d710154..dd36b06ff 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/aggregations/value_count_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/aggregations/value_count_spec.rb @@ -27,20 +27,17 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Aggregations::ValueCount do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(value_count: {}) end end - context '#initialize' do - + describe '#initialize' do let(:search) do described_class.new(foo: 'bar') end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/and_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/and_spec.rb index 0e7cfa163..8ce4b50c8 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/and_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/and_spec.rb @@ -27,20 +27,17 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::And do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(and: {}) end end context 'when enumerable methods are called' do - before do search << { term: { foo: 'bar' } } search << { term: { moo: 'mam' } } @@ -54,20 +51,17 @@ end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do - described_class.new(filters: [ { term: { foo: 'bar' } } ]) + described_class.new(filters: [{ term: { foo: 'bar' } }]) end it 'applies the hash' do - expect(search.to_hash).to eq(and: { filters: [ { term: { foo: 'bar' } } ] }) + expect(search.to_hash).to eq(and: { filters: [{ term: { foo: 'bar' } }] }) end end context 'when a block is provided' do - let(:search) do described_class.new do term foo: 'bar' @@ -76,7 +70,7 @@ end it 'executes the block' do - expect(search.to_hash).to eq(and: [ { term: { foo: 'bar' } }, { term: { moo: 'mam' } } ]) + expect(search.to_hash).to eq(and: [{ term: { foo: 'bar' } }, { term: { moo: 'mam' } }]) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/bool_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/bool_spec.rb index 4a5e57469..7dea7477f 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/bool_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/bool_spec.rb @@ -27,83 +27,73 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Bool do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(bool: {}) end end describe '#initialize' do - context 'when an object instance is provided' do - let(:search) do - described_class.new.must( OpenSearch::DSL::Search::Filters::Term.new foo: 'bar') + described_class.new.must(OpenSearch::DSL::Search::Filters::Term.new(foo: 'bar')) end it 'applies the condition' do - expect(search.to_hash).to eq(bool: { must: [ { term: { foo: 'bar' } } ] }) + expect(search.to_hash).to eq(bool: { must: [{ term: { foo: 'bar' } }] }) end context 'when the block calls multiple methods' do - let(:search) do described_class.new do - must(OpenSearch::DSL::Search::Filters::Term.new foo: 'bar') - must_not(OpenSearch::DSL::Search::Filters::Term.new moo: 'bam') - should(OpenSearch::DSL::Search::Filters::Term.new xoo: 'bax') + must(OpenSearch::DSL::Search::Filters::Term.new(foo: 'bar')) + must_not(OpenSearch::DSL::Search::Filters::Term.new(moo: 'bam')) + should(OpenSearch::DSL::Search::Filters::Term.new(xoo: 'bax')) end end it 'executes the block' do expect(search.to_hash).to eq(bool: - { must: [ { term: { foo: 'bar' } } ], - must_not: [ { term: { moo: 'bam' } } ], - should: [ { term: { xoo: 'bax' } } ] - }) + { must: [{ term: { foo: 'bar' } }], + must_not: [{ term: { moo: 'bam' } }], + should: [{ term: { xoo: 'bax' } }] }) end end context 'when the block calls multiple conditions' do - let(:search) do described_class.new do - must(OpenSearch::DSL::Search::Filters::Term.new foo: 'bar') - must(OpenSearch::DSL::Search::Filters::Term.new moo: 'bam') + must(OpenSearch::DSL::Search::Filters::Term.new(foo: 'bar')) + must(OpenSearch::DSL::Search::Filters::Term.new(moo: 'bam')) - should(OpenSearch::DSL::Search::Filters::Term.new xoo: 'bax') - should(OpenSearch::DSL::Search::Filters::Term.new zoo: 'baz') + should(OpenSearch::DSL::Search::Filters::Term.new(xoo: 'bax')) + should(OpenSearch::DSL::Search::Filters::Term.new(zoo: 'baz')) end end it 'executes the block' do expect(search.to_hash).to eq(bool: - { must: [ { term: { foo: 'bar' } }, { term: { moo: 'bam' } } ], - should: [ { term: { xoo: 'bax' } }, { term: { zoo: 'baz' } } ] - }) + { must: [{ term: { foo: 'bar' } }, { term: { moo: 'bam' } }], + should: [{ term: { xoo: 'bax' } }, { term: { zoo: 'baz' } }] }) end end end context 'when a hash is provided' do - let(:search) do - described_class.new(must: [ { term: { foo: 'bar' } } ]) + described_class.new(must: [{ term: { foo: 'bar' } }]) end it 'applies the hash' do - expect(search.to_hash).to eq(bool: { must: [ { term: { foo: 'bar' } } ] }) + expect(search.to_hash).to eq(bool: { must: [{ term: { foo: 'bar' } }] }) end end context 'when a block is provided' do - let(:search) do described_class.new do must { term foo: 'bar' } @@ -111,11 +101,10 @@ end it 'executes the block' do - expect(search.to_hash).to eq(bool: { must: [ { term: { foo: 'bar' } } ] }) + expect(search.to_hash).to eq(bool: { must: [{ term: { foo: 'bar' } }] }) end context 'when the block calls multiple methods' do - let(:search) do described_class.new do must { term foo: 'bar' } @@ -126,15 +115,13 @@ it 'executes the block' do expect(search.to_hash).to eq(bool: - { must: [ { term: { foo: 'bar' } } ], - must_not: [ { term: { moo: 'bam' } } ], - should: [ { term: { xoo: 'bax' } } ] - }) + { must: [{ term: { foo: 'bar' } }], + must_not: [{ term: { moo: 'bam' } }], + should: [{ term: { xoo: 'bax' } }] }) end end context 'when the block calls multiple conditions' do - let(:search) do described_class.new do must { term foo: 'bar' } @@ -147,50 +134,45 @@ it 'executes the block' do expect(search.to_hash).to eq(bool: - { must: [ { term: { foo: 'bar' } }, { term: { moo: 'bam' } } ], - should: [ { term: { xoo: 'bax' } }, { term: { zoo: 'baz' } } ] - }) + { must: [{ term: { foo: 'bar' } }, { term: { moo: 'bam' } }], + should: [{ term: { xoo: 'bax' } }, { term: { zoo: 'baz' } }] }) end end end end describe '#must' do - before do search.must { term foo: 'bar' } end it 'applies the condition' do - expect(search.to_hash).to eq(bool: { must: [ { term: { foo: 'bar' } } ] }) + expect(search.to_hash).to eq(bool: { must: [{ term: { foo: 'bar' } }] }) end context 'when the method is called more than once' do - before do search.must { term foo: 'bar' } search.must { term moo: 'bam' } end it 'applies the conditions' do - expect(search.to_hash).to eq(bool: { must: [ { term: { foo: 'bar' } }, { term: { moo: 'bam' } } ] }) + expect(search.to_hash).to eq(bool: { must: [{ term: { foo: 'bar' } }, { term: { moo: 'bam' } }] }) end end end describe '#should' do - before do search.should { term xoo: 'bax' } end it 'applies the condition' do - expect(search.to_hash).to eq(bool: { should: [ { term: { xoo: 'bax' } } ] }) + expect(search.to_hash).to eq(bool: { should: [{ term: { xoo: 'bax' } }] }) end end context 'when methods are chained' do - before do search.must { term foo: 'bar' } search.must { term foo: 'baz' }.must { term moo: 'bam' } @@ -201,7 +183,7 @@ it 'applies all the conditions' do expect(search.to_hash).to eq(bool: { must: [{ term: { foo: 'bar' } }, { term: { foo: 'baz' } }, { term: { moo: 'bam' } }], - must_not: [{ term: { foo: 'biz' } }], + must_not: [{ term: { foo: 'biz' } }], should: [{ term: { foo: 'bor' } }] }) end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/exists_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/exists_spec.rb index 609083f24..6af443358 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/exists_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/exists_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Exists do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(exists: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('bar') end @@ -58,9 +54,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_bounding_box_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_bounding_box_spec.rb index eec447796..2f7464192 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_bounding_box_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_bounding_box_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::GeoBoundingBox do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#top_left' do - before do search.top_left('bar') end @@ -57,7 +53,6 @@ end describe '#bottom_right' do - before do search.bottom_right('bar') end @@ -68,7 +63,6 @@ end describe '#top_right' do - before do search.top_right('bar') end @@ -79,7 +73,6 @@ end describe '#bottom_left' do - before do search.bottom_left('bar') end @@ -90,7 +83,6 @@ end describe '#top' do - before do search.top('bar') end @@ -101,7 +93,6 @@ end describe '#left' do - before do search.left('bar') end @@ -112,7 +103,6 @@ end describe '#bottom' do - before do search.bottom('bar') end @@ -123,7 +113,6 @@ end describe '#right' do - before do search.right('bar') end @@ -135,18 +124,16 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do - top_left [0,1] - bottom_right [3,2] + top_left [0, 1] + bottom_right [3, 2] end end it 'executes the block' do - expect(search.to_hash).to eq(geo_bounding_box: { top_left: [0,1], bottom_right: [3,2] }) + expect(search.to_hash).to eq(geo_bounding_box: { top_left: [0, 1], bottom_right: [3, 2] }) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_distance_range_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_distance_range_spec.rb index f0e572e5e..0640ad702 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_distance_range_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_distance_range_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::GeoDistanceRange do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#lat' do - before do search.lat('bar') end @@ -57,7 +53,6 @@ end describe '#lon' do - before do search.lon('bar') end @@ -69,13 +64,11 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do lat 40 - lon -70 + lon(-70) end end @@ -84,11 +77,10 @@ end context 'when options are also provided' do - let(:search) do described_class.new :foo, from: '10km', to: '20km' do lat 40 - lon -70 + lon(-70) end end @@ -99,7 +91,6 @@ end context 'when options are provided' do - let(:search) do described_class.new(from: '10km', to: '20km', foo: { lat: 40, lon: -70 }) end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_distance_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_distance_spec.rb index 99e9ecb04..c60cfd60c 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_distance_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_distance_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::GeoDistance do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#distance' do - before do search.distance('bar') end @@ -57,7 +53,6 @@ end describe '#distance_type' do - before do search.distance_type('bar') end @@ -68,7 +63,6 @@ end describe '#lat' do - before do search.lat('bar') end @@ -79,7 +73,6 @@ end describe '#lon' do - before do search.lon('bar') end @@ -91,14 +84,12 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new :foo do distance '1km' lat 40 - lon -70 + lon(-70) end end @@ -107,11 +98,10 @@ end context 'when options are also provided' do - let(:search) do described_class.new(:foo, distance: '10km') do lat 40 - lon -70 + lon(-70) end end @@ -122,7 +112,6 @@ end context 'when options are provided' do - let(:search) do described_class.new(distance: '10km', foo: { lat: 40, lon: -70 }) end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_polygon_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_polygon_spec.rb index 83b54894a..2c912848a 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_polygon_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_polygon_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::GeoPolygon do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#points' do - before do search.points('bar') end @@ -58,9 +54,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new :foo do points 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_shape_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_shape_spec.rb index 81d88f342..8f881d2f6 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_shape_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/geo_shape_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::GeoShape do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#shape' do - before do search.shape('bar') end @@ -57,7 +53,6 @@ end describe '#indexed_shape' do - before do search.indexed_shape('bar') end @@ -69,9 +64,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new :foo do shape 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/geohash_cell_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/geohash_cell_spec.rb index 15ca72804..555aafc91 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/geohash_cell_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/geohash_cell_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::GeohashCell do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#precision' do - before do search.precision('bar') end @@ -57,7 +53,6 @@ end describe '#neighbors' do - before do search.neighbors('bar') end @@ -68,7 +63,6 @@ end describe '#lat' do - before do search.lat('bar') end @@ -79,7 +73,6 @@ end describe '#lon' do - before do search.lon('bar') end @@ -91,9 +84,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new :foo do lat 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/has_child_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/has_child_spec.rb index d6d2e616a..59dbb74e5 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/has_child_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/has_child_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::HasChild do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#type' do - before do search.type('bar') end @@ -57,7 +53,6 @@ end describe '#query' do - before do search.query('bar') end @@ -68,7 +63,6 @@ end describe '#filter' do - before do search.filter('bar') end @@ -79,7 +73,6 @@ end describe '#min_children' do - before do search.min_children('bar') end @@ -90,7 +83,6 @@ end describe '#max_children' do - before do search.max_children('bar') end @@ -101,7 +93,6 @@ end describe '#inner_hits' do - before do search.inner_hits(size: 1) end @@ -113,9 +104,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do type 'bar' @@ -128,7 +117,6 @@ end context 'when a block is provided to an option method' do - let(:search) do described_class.new do type 'bar' @@ -141,7 +129,7 @@ end it 'executes the block' do - expect(search.to_hash).to eq(has_child: { type: 'bar', query: { match: { foo: { query: 'bar'} } } }) + expect(search.to_hash).to eq(has_child: { type: 'bar', query: { match: { foo: { query: 'bar' } } } }) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/has_parent_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/has_parent_spec.rb index 00a778231..6fcbbf54f 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/has_parent_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/has_parent_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::HasParent do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#parent_type' do - before do search.parent_type('bar') end @@ -57,7 +53,6 @@ end describe '#query' do - before do search.query('bar') end @@ -68,7 +63,6 @@ end describe '#filter' do - before do search.filter('bar') end @@ -79,7 +73,6 @@ end describe '#score_mode' do - before do search.score_mode('bar') end @@ -90,7 +83,6 @@ end describe '#inner_hits' do - before do search.inner_hits(size: 1) end @@ -102,9 +94,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do parent_type 'bar' @@ -117,7 +107,6 @@ end context 'when a block is provided to an option method' do - let(:search) do described_class.new do parent_type 'bar' @@ -130,7 +119,7 @@ end it 'executes the block' do - expect(search.to_hash).to eq(has_parent: { parent_type: 'bar', query: { match: { foo: { query: 'bar'} } } }) + expect(search.to_hash).to eq(has_parent: { parent_type: 'bar', query: { match: { foo: { query: 'bar' } } } }) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/ids_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/ids_spec.rb index 11eed3914..c3b22a2a9 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/ids_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/ids_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Ids do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#type' do - before do search.type('bar') end @@ -57,7 +53,6 @@ end describe '#values' do - before do search.values('bar') end @@ -69,18 +64,16 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do type 'bar' - values ['1', '2', '3'] + values %w[1 2 3] end end it 'executes the block' do - expect(search.to_hash).to eq(ids: { type: 'bar', values: ['1', '2', '3'] }) + expect(search.to_hash).to eq(ids: { type: 'bar', values: %w[1 2 3] }) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/indices_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/indices_spec.rb index b30fc1ebe..503b131c8 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/indices_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/indices_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Indices do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#indices' do - before do search.indices('bar') end @@ -57,7 +53,6 @@ end describe '#filter' do - before do search.filter('bar') end @@ -68,7 +63,6 @@ end describe '#no_match_filter' do - before do search.no_match_filter('bar') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do indices 'bar' @@ -95,7 +87,6 @@ end context 'when a block is provided to an option method' do - let(:search) do described_class.new do indices 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/limit_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/limit_spec.rb index 2b1eefdde..bddaceb84 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/limit_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/limit_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Limit do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(limit: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#value' do - before do search.value('bar') end @@ -58,9 +54,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do value 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/match_all_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/match_all_spec.rb index 852c7698b..90ff269b8 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/match_all_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/match_all_spec.rb @@ -27,13 +27,11 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::MatchAll do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(match_all: {}) end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/missing_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/missing_spec.rb index 446fe3864..c5f3d26a0 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/missing_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/missing_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Missing do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(missing: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#field' do - before do search.field('bar') end @@ -58,9 +54,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/nested_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/nested_spec.rb index 1a8134757..922f26ef3 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/nested_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/nested_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Nested do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(nested: {}) end end context 'when options methods are called' do - let(:search) do described_class.new end describe '#path' do - before do search.path('bar') end @@ -57,7 +53,6 @@ end describe '#query' do - before do search.query('bar') end @@ -68,7 +63,6 @@ end describe '#filter' do - before do search.filter('bar') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do path 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/not_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/not_spec.rb index 90f648668..147656d2a 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/not_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/not_spec.rb @@ -27,33 +27,28 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Not do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(not: {}) end end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do - described_class.new(filters: [ { term: { foo: 'bar' } } ]) + described_class.new(filters: [{ term: { foo: 'bar' } }]) end it 'applies the hash' do - expect(search.to_hash).to eq(not: { filters: [ { term: { foo: 'bar' } } ] }) + expect(search.to_hash).to eq(not: { filters: [{ term: { foo: 'bar' } }] }) end end context 'when a block is provided' do - let(:search) do described_class.new do term foo: 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/or_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/or_spec.rb index 2664dc6a8..abdc541db 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/or_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/or_spec.rb @@ -27,7 +27,6 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Or do - let(:search) do described_class.new end @@ -37,27 +36,23 @@ end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(or: {}) end end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do - described_class.new(filters: [ { term: { foo: 'bar' } } ]) + described_class.new(filters: [{ term: { foo: 'bar' } }]) end it 'applies the hash' do - expect(search.to_hash).to eq(or: { filters: [ { term: { foo: 'bar' } } ] }) + expect(search.to_hash).to eq(or: { filters: [{ term: { foo: 'bar' } }] }) end end context 'when a block is provided' do - let(:search) do described_class.new do term foo: 'bar' @@ -66,19 +61,18 @@ end it 'executes the block' do - expect(search.to_hash).to eq(or: [ {term: { foo: 'bar'}}, {term: { moo: 'mam'}} ]) + expect(search.to_hash).to eq(or: [{ term: { foo: 'bar' } }, { term: { moo: 'mam' } }]) end end end context 'when the filter is appended to' do - before do search << { term: { foo: 'bar' } } end it 'appends the predicate' do - expect(search.to_hash).to eq(or: [ { term: { foo: 'bar' } } ]) + expect(search.to_hash).to eq(or: [{ term: { foo: 'bar' } }]) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/prefix_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/prefix_spec.rb index 0ae8029d1..6ff0d9937 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/prefix_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/prefix_spec.rb @@ -27,22 +27,18 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Prefix do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(prefix: {}) end end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do described_class.new(foo: 'bar') end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/query_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/query_spec.rb index 86792f096..f07d70117 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/query_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/query_spec.rb @@ -27,22 +27,18 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Query do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(query: {}) end end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do described_class.new(query_string: { query: 'foo' }) end @@ -53,7 +49,6 @@ end context 'when a block is provided' do - let(:search) do described_class.new do match foo: 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/range_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/range_spec.rb index f49975fd0..099d006e6 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/range_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/range_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Range do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(range: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#gte' do - before do search.gte('bar') end @@ -57,7 +53,6 @@ end describe '#lte' do - before do search.lte('bar') end @@ -68,7 +63,6 @@ end describe '#time_zone' do - before do search.time_zone('bar') end @@ -79,7 +73,6 @@ end describe '#format' do - before do search.format('bar') end @@ -91,9 +84,7 @@ end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do described_class.new(age: { gte: 10, lte: 20 }) end @@ -104,7 +95,6 @@ end context 'when a block is provided' do - let(:search) do described_class.new(:age) do gte 10 diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/regexp_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/regexp_spec.rb index c17063edd..044a14297 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/regexp_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/regexp_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Regexp do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(regexp: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#value' do - before do search.value('bar') end @@ -57,7 +53,6 @@ end describe '#flags' do - before do search.flags('bar') end @@ -69,9 +64,7 @@ end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do described_class.new(foo: 'b.*r') end @@ -82,7 +75,6 @@ end context 'when a block is provided' do - let(:search) do described_class.new(:foo) do value 'b*r' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/script_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/script_spec.rb index 49868ddf7..c0f678d1c 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/script_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/script_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Script do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(script: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#script' do - before do search.script('bar') end @@ -57,7 +53,6 @@ end describe '#params' do - before do search.params(foo: 'bar') end @@ -69,9 +64,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do script 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/term_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/term_spec.rb index 7faaf9a6a..7bb398fa4 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/term_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/term_spec.rb @@ -27,22 +27,18 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Term do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(term: {}) end end describe '#initialize' do - context 'when a scalar is specified' do - let(:search) do described_class.new(message: 'test') end @@ -53,7 +49,6 @@ end context 'when a hash is specified' do - let(:search) do described_class.new(message: { query: 'test' }) end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/terms_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/terms_spec.rb index d0ca346f2..12cd13f65 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/terms_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/terms_spec.rb @@ -27,28 +27,24 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Terms do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(terms: {}) end end describe '#initialize' do - context 'when a hash is specified' do - let(:search) do - described_class.new(foo: ['abc', 'xyz']) + described_class.new(foo: %w[abc xyz]) end it 'sets the value' do - expect(search.to_hash).to eq(terms: { foo: ['abc', 'xyz'] }) + expect(search.to_hash).to eq(terms: { foo: %w[abc xyz] }) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/filters/type_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/filters/type_spec.rb index 11164c4f6..5f68758c8 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/filters/type_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/filters/type_spec.rb @@ -27,26 +27,22 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Filters::Type do - let(:search) do described_class.new end describe '#to_hash' do - it 'can be converted to a hash' do expect(search.to_hash).to eq(type: {}) end end context 'when options methods are called' do - let(:search) do described_class.new(:foo) end describe '#value' do - before do search.value('bar') end @@ -58,9 +54,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do value 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/bool_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/bool_spec.rb index d6a7e8657..0abd32472 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/bool_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/bool_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Bool do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,19 +38,16 @@ end describe '#initialize' do - context 'when an object instance is provided' do - let(:search) do - described_class.new.must(OpenSearch::DSL::Search::Queries::Match.new foo: 'bar') + described_class.new.must(OpenSearch::DSL::Search::Queries::Match.new(foo: 'bar')) end it 'applies the condition' do - expect(search.to_hash).to eq(bool: {must: [ {match: { foo: 'bar' }} ] }) + expect(search.to_hash).to eq(bool: { must: [{ match: { foo: 'bar' } }] }) end context 'when multiple option methods are called' do - let(:search) do described_class.new do should(OpenSearch::DSL::Search::Queries::Term.new(tag: 'wow')) @@ -65,33 +60,31 @@ it 'defines all the options' do expect(search.to_hash).to eq(bool: { - minimum_should_match: 1, - boost: 1.0, - should: [ {term: { tag: 'wow' }}, {term: { tag: 'opensearch' }} ]}) + minimum_should_match: 1, + boost: 1.0, + should: [{ term: { tag: 'wow' } }, { term: { tag: 'opensearch' } }] + }) end end context 'when multiple conditions are provided' do - let(:search) do described_class.new do - must(OpenSearch::DSL::Search::Queries::Match.new foo: 'bar') - must(OpenSearch::DSL::Search::Queries::Match.new moo: 'bam') + must(OpenSearch::DSL::Search::Queries::Match.new(foo: 'bar')) + must(OpenSearch::DSL::Search::Queries::Match.new(moo: 'bam')) - should(OpenSearch::DSL::Search::Queries::Match.new xoo: 'bax') - should(OpenSearch::DSL::Search::Queries::Match.new zoo: 'baz') + should(OpenSearch::DSL::Search::Queries::Match.new(xoo: 'bax')) + should(OpenSearch::DSL::Search::Queries::Match.new(zoo: 'baz')) end end it 'applies each condition' do expect(search.to_hash).to eq(bool: - { must: [ {match: { foo: 'bar' }}, {match: { moo: 'bam' }} ], - should: [ {match: { xoo: 'bax' }}, {match: { zoo: 'baz' }} ] - }) + { must: [{ match: { foo: 'bar' } }, { match: { moo: 'bam' } }], + should: [{ match: { xoo: 'bax' } }, { match: { zoo: 'baz' } }] }) end context 'when #to_hash is called more than once' do - it 'does not alter the hash' do expect(search.to_hash).to eq(search.to_hash) end @@ -100,7 +93,6 @@ end context 'when a block is provided' do - let(:search) do described_class.new do must { match foo: 'bar' } @@ -108,11 +100,10 @@ end it 'executes the block' do - expect(search.to_hash).to eq(bool: {must: [ {match: { foo: 'bar' }} ] }) + expect(search.to_hash).to eq(bool: { must: [{ match: { foo: 'bar' } }] }) end context 'when multiple option methods are called' do - let(:search) do described_class.new do should { term tag: 'wow' } @@ -125,14 +116,14 @@ it 'defines all the options' do expect(search.to_hash).to eq(bool: { - minimum_should_match: 1, - boost: 1.0, - should: [ {term: { tag: 'wow' }}, {term: { tag: 'opensearch' }} ]}) + minimum_should_match: 1, + boost: 1.0, + should: [{ term: { tag: 'wow' } }, { term: { tag: 'opensearch' } }] + }) end end context 'when multiple conditions are provided' do - let(:search) do described_class.new do must do @@ -155,13 +146,11 @@ it 'applies each condition' do expect(search.to_hash).to eq(bool: - { must: [ {match: { foo: 'bar' }}, {match: { moo: 'bam' }} ], - should: [ {match: { xoo: 'bax' }}, {match: { zoo: 'baz' }} ] - }) + { must: [{ match: { foo: 'bar' } }, { match: { moo: 'bam' } }], + should: [{ match: { xoo: 'bax' } }, { match: { zoo: 'baz' } }] }) end context 'when #to_hash is called more than once' do - it 'does not alter the hash' do expect(search.to_hash).to eq(search.to_hash) end @@ -171,7 +160,6 @@ end context 'when options methods are called' do - let(:search) do described_class.new end @@ -183,13 +171,12 @@ end it 'applies the option' do - expect(search.to_hash).to eq(bool: { must: [ {match: { foo: 'bar' }}, {match: { moo: 'bam' }} ], - should: [ {match: { xoo: 'bax' }} ] }) + expect(search.to_hash).to eq(bool: { must: [{ match: { foo: 'bar' } }, { match: { moo: 'bam' } }], + should: [{ match: { xoo: 'bax' } }] }) end end context 'when the filter method is called multiple times' do - let(:search) do described_class.new end @@ -202,14 +189,13 @@ it 'combines the filter clauses' do expect(search.to_hash).to eq(bool: { filter: [ - { term: { foo: "bar"}}, - { term: { zoo: "baz"}} + { term: { foo: 'bar' } }, + { term: { zoo: 'baz' } } ] }) end end context 'when methods are chained' do - let(:search) do described_class.new end @@ -219,15 +205,13 @@ end it 'applies the option' do - expect(search.to_hash).to eq(bool: { must: [ {match: { foo: 'bar' }}, {match: { moo: 'bam' }} ], - should: [ {match: { xoo: 'bax' }} ] }) + expect(search.to_hash).to eq(bool: { must: [{ match: { foo: 'bar' } }, { match: { moo: 'bam' } }], + should: [{ match: { xoo: 'bax' } }] }) end end describe '#filter' do - context 'when a block is used to define the filter' do - let(:search) do described_class.new do filter do @@ -242,9 +226,7 @@ end context 'when a filter is passed as an argument' do - context 'when the filter is a hash' do - let(:search) do described_class.new do filter(term: { foo: 'Foo!' }) @@ -257,7 +239,6 @@ end context 'when the filter is a `OpenSearch::DSL::Search::Filter` object' do - let(:search) do filter_object = OpenSearch::DSL::Search::Filter.new do term bar: 'Bar!' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/boosting_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/boosting_spec.rb index b8092142d..283b4d286 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/boosting_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/boosting_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Boosting do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#positive' do - before do search.positive('bar') end @@ -57,7 +53,6 @@ end describe '#negative' do - before do search.negative('bar') end @@ -68,7 +63,6 @@ end describe '#negative_boost' do - before do search.negative_boost('bar') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do positive foo: 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/common_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/common_spec.rb index 117032ea2..ed3ef66df 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/common_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/common_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Common do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#query' do - before do search.query('bar') end @@ -57,7 +53,6 @@ end describe '#cutoff_frequency' do - before do search.cutoff_frequency('bar') end @@ -68,7 +63,6 @@ end describe '#low_freq_operator' do - before do search.low_freq_operator('bar') end @@ -79,7 +73,6 @@ end describe '#minimum_should_match' do - before do search.minimum_should_match('bar') end @@ -90,7 +83,6 @@ end describe '#boost' do - before do search.boost('bar') end @@ -101,7 +93,6 @@ end describe '#analyzer' do - before do search.analyzer('bar') end @@ -112,7 +103,6 @@ end describe '#disable_coord' do - before do search.disable_coord('bar') end @@ -124,9 +114,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do query 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/constant_score_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/constant_score_spec.rb index 1bb6fac30..9bbe7061a 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/constant_score_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/constant_score_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::ConstantScore do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#query' do - before do search.query('bar') end @@ -57,7 +53,6 @@ end describe '#filter' do - before do search.filter('bar') end @@ -68,7 +63,6 @@ end describe '#boost' do - before do search.boost('bar') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do query do diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/dis_max_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/dis_max_spec.rb index 237185f8d..93c424087 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/dis_max_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/dis_max_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::DisMax do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#tie_breaker' do - before do search.tie_breaker('bar') end @@ -57,7 +53,6 @@ end describe '#boost' do - before do search.boost('bar') end @@ -68,7 +63,6 @@ end describe '#queries' do - before do search.queries('bar') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do tie_breaker 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/exists_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/exists_spec.rb index 594eeafb1..aecd17c13 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/exists_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/exists_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Exists do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#field' do - before do search.field('bar') end @@ -58,9 +54,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do field 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/filtered_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/filtered_spec.rb index e1e3dd08d..1e7a9e158 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/filtered_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/filtered_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Filtered do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#query' do - before do search.query('bar') end @@ -57,7 +53,6 @@ end describe '#filter' do - before do search.filter('bar') end @@ -68,7 +63,6 @@ end describe '#strategy' do - before do search.strategy('bar') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do query do diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/function_score_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/function_score_spec.rb index 4e9b5f161..0832c6203 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/function_score_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/function_score_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::FunctionScore do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#query' do - before do search.query('bar') end @@ -57,7 +53,6 @@ end describe '#filter' do - before do search.filter('bar') end @@ -68,7 +63,6 @@ end describe '#functions' do - before do search.functions('bar') end @@ -78,19 +72,17 @@ end context 'when the option is called as a setter' do - before do - search.functions = [ {foo: { abc: '123' }} ] + search.functions = [{ foo: { abc: '123' } }] end it 'applies the option' do - expect(search.to_hash).to eq(function_score: { functions: [ {foo: { abc: '123' }} ] }) + expect(search.to_hash).to eq(function_score: { functions: [{ foo: { abc: '123' } }] }) end end end describe '#script_score' do - before do search.script_score('bar') end @@ -101,7 +93,6 @@ end describe '#boost' do - before do search.boost('bar') end @@ -112,7 +103,6 @@ end describe '#max_boost' do - before do search.max_boost('bar') end @@ -123,7 +113,6 @@ end describe '#score_mode' do - before do search.score_mode('bar') end @@ -134,7 +123,6 @@ end describe '#boost_mode' do - before do search.boost_mode('bar') end @@ -146,9 +134,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do query do @@ -164,9 +150,10 @@ it 'executes the block' do expect(search.to_hash).to eq(function_score: { - query: { match: { foo: 'BLAM' } }, - filter: { term: { bar: 'slam' } }, - functions: [ { foo: { abc: '123' } }, { foo: { xyz: '456' } } ] }) + query: { match: { foo: 'BLAM' } }, + filter: { term: { bar: 'slam' } }, + functions: [{ foo: { abc: '123' } }, { foo: { xyz: '456' } }] + }) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/fuzzy_like_this_field_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/fuzzy_like_this_field_spec.rb index b213658c2..2a1642cb8 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/fuzzy_like_this_field_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/fuzzy_like_this_field_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::FuzzyLikeThisField do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#like_text' do - before do search.like_text('bar') end @@ -57,7 +53,6 @@ end describe '#fuzziness' do - before do search.fuzziness('bar') end @@ -68,7 +63,6 @@ end describe '#analyzer' do - before do search.analyzer('bar') end @@ -79,7 +73,6 @@ end describe '#max_query_terms' do - before do search.max_query_terms('bar') end @@ -90,7 +83,6 @@ end describe '#prefix_length' do - before do search.prefix_length('bar') end @@ -101,7 +93,6 @@ end describe '#boost' do - before do search.boost('bar') end @@ -112,7 +103,6 @@ end describe '#ignore_tf' do - before do search.ignore_tf('bar') end @@ -124,9 +114,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do like_text 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/fuzzy_like_this_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/fuzzy_like_this_spec.rb index 2169062bf..d101ede57 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/fuzzy_like_this_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/fuzzy_like_this_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::FuzzyLikeThis do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#fields' do - before do search.fields('bar') end @@ -57,7 +53,6 @@ end describe '#like_text' do - before do search.like_text('bar') end @@ -68,7 +63,6 @@ end describe '#fuzziness' do - before do search.fuzziness('bar') end @@ -79,7 +73,6 @@ end describe '#analyzer' do - before do search.analyzer('bar') end @@ -90,7 +83,6 @@ end describe '#max_query_terms' do - before do search.max_query_terms('bar') end @@ -101,7 +93,6 @@ end describe '#prefix_length' do - before do search.prefix_length('bar') end @@ -112,7 +103,6 @@ end describe '#boost' do - before do search.boost('bar') end @@ -124,9 +114,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do fields ['foo'] diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/fuzzy_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/fuzzy_spec.rb index 3e817efde..7d82aee33 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/fuzzy_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/fuzzy_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Fuzzy do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#value' do - before do search.value('bar') end @@ -57,7 +53,6 @@ end describe '#boost' do - before do search.boost('bar') end @@ -68,7 +63,6 @@ end describe '#fuzziness' do - before do search.fuzziness('bar') end @@ -79,7 +73,6 @@ end describe '#prefix_length' do - before do search.prefix_length('bar') end @@ -90,7 +83,6 @@ end describe '#max_expansions' do - before do search.max_expansions('bar') end @@ -102,9 +94,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do value 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/geo_shape_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/geo_shape_spec.rb index 053885d7a..2a5e42557 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/geo_shape_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/geo_shape_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::GeoShape do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#shape' do - before do search.shape('bar') end @@ -57,7 +53,6 @@ end describe '#indexed_shape' do - before do search.indexed_shape('bar') end @@ -69,9 +64,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do shape 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/has_child_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/has_child_spec.rb index 59a5ef653..e655c56f4 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/has_child_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/has_child_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::HasChild do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#type' do - before do search.type('bar') end @@ -57,7 +53,6 @@ end describe '#query' do - before do search.query('bar') end @@ -68,7 +63,6 @@ end describe '#score_mode' do - before do search.score_mode('bar') end @@ -79,7 +73,6 @@ end describe '#min_children' do - before do search.min_children('bar') end @@ -90,7 +83,6 @@ end describe '#max_children' do - before do search.max_children('bar') end @@ -101,7 +93,6 @@ end describe '#inner_hits' do - before do search.inner_hits(size: 1) end @@ -113,9 +104,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do type 'bar' @@ -128,7 +117,7 @@ end it 'executes the block' do - expect(search.to_hash).to eq(has_child: { type: 'bar', query: { match: { foo: { query: 'bar'} } } }) + expect(search.to_hash).to eq(has_child: { type: 'bar', query: { match: { foo: { query: 'bar' } } } }) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/has_parent_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/has_parent_spec.rb index 245513ebc..87a9cdec3 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/has_parent_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/has_parent_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::HasParent do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#parent_type' do - before do search.parent_type('bar') end @@ -57,7 +53,6 @@ end describe '#query' do - before do search.query('bar') end @@ -68,7 +63,6 @@ end describe '#score_mode' do - before do search.score_mode('bar') end @@ -79,7 +73,6 @@ end describe '#inner_hits' do - before do search.inner_hits(size: 1) end @@ -91,9 +84,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do parent_type 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/ids_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/ids_spec.rb index 64654bff9..bb838c84a 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/ids_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/ids_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Ids do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#type' do - before do search.type('bar') end @@ -57,7 +53,6 @@ end describe '#values' do - before do search.values('bar') end @@ -69,9 +64,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do type 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/indices_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/indices_spec.rb index a7cf783c3..250fceebc 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/indices_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/indices_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Indices do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#indices' do - before do search.indices('bar') end @@ -57,7 +53,6 @@ end describe '#query' do - before do search.query('bar') end @@ -68,7 +63,6 @@ end describe '#no_match_query' do - before do search.no_match_query('bar') end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do indices 'bar' @@ -91,7 +83,7 @@ end it 'executes the block' do - expect(search.to_hash).to eq(indices: { indices: 'bar', query: { term: { foo: 'bar' } } } ) + expect(search.to_hash).to eq(indices: { indices: 'bar', query: { term: { foo: 'bar' } } }) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/match_all_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/match_all_spec.rb index 10befcd93..4b6f56b90 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/match_all_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/match_all_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::MatchAll do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#boost' do - before do search.boost('bar') end @@ -58,9 +54,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do boost 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/match_phrase_prefix_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/match_phrase_prefix_spec.rb index ae3ebeccd..c075068fc 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/match_phrase_prefix_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/match_phrase_prefix_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::MatchPhrasePrefix do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#query' do - before do search.query('bar') end @@ -57,7 +53,6 @@ end describe '#boost' do - before do search.boost(10) end @@ -68,7 +63,6 @@ end describe '#max_expansions' do - before do search.max_expansions(2) end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do described_class.new(message: 'test') end @@ -93,7 +85,6 @@ end context 'when a block is provided' do - let(:search) do described_class.new do query 'test' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/match_phrase_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/match_phrase_spec.rb index 7437b09d5..61d09eae6 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/match_phrase_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/match_phrase_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::MatchPhrase do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#query' do - before do search.query('bar') end @@ -57,7 +53,6 @@ end describe '#analyzer' do - before do search.analyzer('standard') end @@ -66,9 +61,8 @@ expect(search.to_hash[:match_phrase][:analyzer]).to eq('standard') end end - - describe '#boost' do + describe '#boost' do before do search.boost(10) end @@ -79,7 +73,6 @@ end describe '#slop' do - before do search.slop(1) end @@ -91,9 +84,7 @@ end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do described_class.new(message: { query: 'test' }) end @@ -104,7 +95,6 @@ end context 'when a block is provided' do - let(:search) do described_class.new do query 'test' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/match_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/match_spec.rb index 90da60651..ae640d6ed 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/match_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/match_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Match do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,13 +38,11 @@ end context 'when options methods are called' do - let(:search) do described_class.new end describe '#query' do - before do search.query('bar') end @@ -57,7 +53,6 @@ end describe '#operator' do - before do search.operator('standard') end @@ -68,7 +63,6 @@ end describe '#type' do - before do search.type(10) end @@ -80,9 +74,7 @@ end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do described_class.new(message: { query: 'test' }) end @@ -93,7 +85,6 @@ end context 'when a block is provided' do - let(:search) do described_class.new do query 'test' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/more_like_this_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/more_like_this_spec.rb index 1527bbb90..7746e6124 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/more_like_this_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/more_like_this_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::MoreLikeThis do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,31 +38,28 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'fields', - 'like_text', - 'min_term_freq', - 'max_query_terms', - 'docs', - 'ids', - 'include', - 'exclude', - 'percent_terms_to_match', - 'stop_words', - 'min_doc_freq', - 'max_doc_freq', - 'min_word_length', - 'max_word_length', - 'boost_terms', - 'boost', - 'analyzer' ].each do |option| - + %w[fields + like_text + min_term_freq + max_query_terms + docs + ids + include + exclude + percent_terms_to_match + stop_words + min_doc_freq + max_doc_freq + min_word_length + max_word_length + boost_terms + boost + analyzer].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -77,18 +72,16 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do - fields ['foo', 'bar'] + fields %w[foo bar] like_text 'abc' end end it 'executes the block' do - expect(search.to_hash[:more_like_this][:fields]).to eq(['foo', 'bar']) + expect(search.to_hash[:more_like_this][:fields]).to eq(%w[foo bar]) expect(search.to_hash[:more_like_this][:like_text]).to eq('abc') end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/multi_match_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/multi_match_spec.rb index ee5b0cf18..1c29fe883 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/multi_match_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/multi_match_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::MultiMatch do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,18 +38,15 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'query', - 'fields', - 'type', - 'use_dis_max' ].each do |option| - + %w[query + fields + type + use_dis_max].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -64,18 +59,16 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do query 'bar' - fields ['a', 'b'] + fields %w[a b] end end it 'executes the block' do - expect(search.to_hash[:multi_match][:fields]).to eq(['a', 'b']) + expect(search.to_hash[:multi_match][:fields]).to eq(%w[a b]) expect(search.to_hash[:multi_match][:query]).to eq('bar') end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/nested_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/nested_spec.rb index 0625323ab..b3ba24efa 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/nested_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/nested_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Nested do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,18 +38,15 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'path', - 'score_mode', - 'score_mode', - 'query' ].each do |option| - + %w[path + score_mode + score_mode + query].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -62,7 +57,6 @@ end describe '#inner_hits' do - before do search.inner_hits(size: 1) end @@ -73,7 +67,6 @@ end describe '#query' do - before do search.query(match: { foo: 'bar' }) end @@ -86,9 +79,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do path 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/prefix_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/prefix_spec.rb index 08f87ee79..52d13ef8a 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/prefix_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/prefix_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Prefix do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,16 +38,13 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'value', - 'boost'].each do |option| - + %w[value + boost].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -62,9 +57,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do value 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/query_string_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/query_string_spec.rb index d15852859..88aa1d57e 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/query_string_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/query_string_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::QueryString do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,35 +38,32 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'query', - 'fields', - 'type', - 'default_field', - 'default_operator', - 'allow_leading_wildcard', - 'lowercase_expanded_terms', - 'enable_position_increments', - 'fuzzy_max_expansions', - 'fuzziness', - 'fuzzy_prefix_length', - 'phrase_slop', - 'boost', - 'analyze_wildcard', - 'auto_generate_phrase_queries', - 'minimum_should_match', - 'lenient', - 'locale', - 'use_dis_max', - 'tie_breaker', - 'time_zone'].each do |option| - + %w[query + fields + type + default_field + default_operator + allow_leading_wildcard + lowercase_expanded_terms + enable_position_increments + fuzzy_max_expansions + fuzziness + fuzzy_prefix_length + phrase_slop + boost + analyze_wildcard + auto_generate_phrase_queries + minimum_should_match + lenient + locale + use_dis_max + tie_breaker + time_zone].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -81,9 +76,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do query 'foo AND bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/range_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/range_spec.rb index 074d71b5f..e56d3c4bd 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/range_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/range_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Range do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,18 +38,15 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'gte', - 'lte', - 'boost', - 'format'].each do |option| - + %w[gte + lte + boost + format].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -64,9 +59,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do gte 10 diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/regexp_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/regexp_spec.rb index e5791eefa..fcb2570c7 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/regexp_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/regexp_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Regexp do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,17 +38,14 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'value', - 'boost', - 'flags'].each do |option| - + %w[value + boost + flags].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -63,9 +58,7 @@ end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do described_class.new(foo: 'b.*r') end @@ -76,7 +69,6 @@ end context 'when a block is provided' do - let(:search) do described_class.new(:foo) do value 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/simple_query_string_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/simple_query_string_spec.rb index 93c8717f6..46cddb17b 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/simple_query_string_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/simple_query_string_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::SimpleQueryString do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,20 +38,17 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'query', - 'fields', - 'default_operator', - 'analyzer', - 'flags', - 'lenient'].each do |option| - + %w[query + fields + default_operator + analyzer + flags + lenient].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -66,9 +61,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new(:foo) do query 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/span_first_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/span_first_spec.rb index 1f9cef271..f7a812d05 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/span_first_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/span_first_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::SpanFirst do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,15 +38,12 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'match' ].each do |option| - + ['match'].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -61,9 +56,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do match 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/span_multi_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/span_multi_spec.rb index d050c7178..111339a36 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/span_multi_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/span_multi_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::SpanMulti do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,15 +38,12 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'match' ].each do |option| - + ['match'].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -61,9 +56,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do match 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/span_near_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/span_near_spec.rb index 25438b405..a452d8761 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/span_near_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/span_near_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::SpanNear do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,18 +38,15 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'span_near', - 'slop', - 'in_order', - 'collect_payloads' ].each do |option| - + %w[span_near + slop + in_order + collect_payloads].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -64,9 +59,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do span_near 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/span_not_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/span_not_spec.rb index f86d75743..ea146428c 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/span_not_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/span_not_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::SpanNot do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,19 +38,16 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'include', - 'exclude', - 'pre', - 'post', - 'dist' ].each do |option| - + %w[include + exclude + pre + post + dist].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -65,9 +60,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do include 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/span_or_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/span_or_spec.rb index 999c0c82e..e399f657f 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/span_or_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/span_or_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::SpanOr do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,15 +38,12 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'clauses' ].each do |option| - + ['clauses'].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -61,9 +56,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do clauses 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/span_term_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/span_term_spec.rb index c98b28d3f..7cde985da 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/span_term_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/span_term_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::SpanTerm do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,9 +38,7 @@ end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do described_class.new(foo: 'bar') end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/template_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/template_spec.rb index 6e28ab012..555bba20a 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/template_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/template_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Template do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,16 +38,13 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'query', - 'params' ].each do |option| - + %w[query + params].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -62,9 +57,7 @@ end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do described_class.new(query: 'bar', params: { foo: 'abc' }) end @@ -76,7 +69,6 @@ end context 'when a block is provided' do - let(:search) do described_class.new do query 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/term_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/term_spec.rb index 31d2af7be..c63ba340a 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/term_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/term_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Term do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,9 +38,7 @@ end describe '#initialize' do - context 'when a String is provided' do - let(:search) do described_class.new(message: 'test') end @@ -53,7 +49,6 @@ end context 'when a hash is provided' do - let(:search) do described_class.new(message: { query: 'test', boost: 2 }) end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/terms_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/terms_spec.rb index eec2ade5f..0b9e6d697 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/terms_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/terms_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Terms do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,15 +38,13 @@ end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do - described_class.new(foo: ['abc', 'xyz']) + described_class.new(foo: %w[abc xyz]) end it 'sets the value' do - expect(search.to_hash[:terms]).to eq(foo: ['abc', 'xyz']) + expect(search.to_hash[:terms]).to eq(foo: %w[abc xyz]) end end end diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/top_children_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/top_children_spec.rb index 6dae7f66b..f73caad95 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/top_children_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/top_children_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::TopChildren do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,20 +38,17 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'type', - 'query', - 'score', - 'factor', - 'incremental_factor', - '_scope' ].each do |option| - + %w[type + query + score + factor + incremental_factor + _scope].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -66,9 +61,7 @@ end describe '#initialize' do - context 'when a block is provided' do - let(:search) do described_class.new do type 'bar' @@ -83,7 +76,6 @@ end context 'when nested blocks are provided' do - let(:search) do described_class.new do type 'bar' diff --git a/opensearch-dsl/spec/opensearch/dsl/search/queries/wildcard_spec.rb b/opensearch-dsl/spec/opensearch/dsl/search/queries/wildcard_spec.rb index b80c7bc62..3e2773b51 100644 --- a/opensearch-dsl/spec/opensearch/dsl/search/queries/wildcard_spec.rb +++ b/opensearch-dsl/spec/opensearch/dsl/search/queries/wildcard_spec.rb @@ -27,9 +27,7 @@ require 'spec_helper' describe OpenSearch::DSL::Search::Queries::Wildcard do - describe '#to_hash' do - let(:search) do described_class.new end @@ -40,16 +38,13 @@ end context 'when options methods are called' do - let(:search) do described_class.new end - [ 'value', - 'boost' ].each do |option| - + %w[value + boost].each do |option| describe "##{option}" do - before do search.send(option, 'bar') end @@ -62,9 +57,7 @@ end describe '#initialize' do - context 'when a hash is provided' do - let(:search) do described_class.new(foo: 'bar') end @@ -75,7 +68,6 @@ end context 'when a block is provided' do - let(:search) do described_class.new do value 'bar' diff --git a/opensearch-dsl/test/integration/search_aggregation_children_test.rb b/opensearch-dsl/test/integration/search_aggregation_children_test.rb index 853e59a56..7cd4306da 100644 --- a/opensearch-dsl/test/integration/search_aggregation_children_test.rb +++ b/opensearch-dsl/test/integration/search_aggregation_children_test.rb @@ -31,18 +31,17 @@ module Test class ChildrenAggregationIntegrationTest < ::OpenSearch::Test::IntegrationTestCase include OpenSearch::DSL::Search - context "A children aggregation" do - + context 'A children aggregation' do setup do @client.indices.create index: 'articles-and-comments', body: { - mappings: { - properties: { - title: {type: 'text'}, - category: {type: 'keyword'}, - join_field: {type: 'join', relations: {article: 'comment'}}, - author: {type: 'keyword'} - } + mappings: { + properties: { + title: { type: 'text' }, + category: { type: 'keyword' }, + join_field: { type: 'join', relations: { article: 'comment' } }, + author: { type: 'keyword' } } + } } @client.index index: 'articles-and-comments', id: 1, @@ -65,7 +64,7 @@ class ChildrenAggregationIntegrationTest < ::OpenSearch::Test::IntegrationTestCa @client.indices.refresh index: 'articles-and-comments' end - should "return the top commenters per article category" do + should 'return the top commenters per article category' do response = @client.search index: 'articles-and-comments', size: 0, body: search { aggregation :top_categories do terms field: 'category' do @@ -80,10 +79,11 @@ class ChildrenAggregationIntegrationTest < ::OpenSearch::Test::IntegrationTestCa end }.to_hash - assert_equal 'one', response['aggregations']['top_categories']['buckets'][0]['key'] - assert_equal 3, response['aggregations']['top_categories']['buckets'][0]['comments']['top_authors']['buckets'].size - assert_equal 'John', response['aggregations']['top_categories']['buckets'][0]['comments']['top_authors']['buckets'][0]['key'] - + assert_equal 'one', response['aggregations']['top_categories']['buckets'][0]['key'] + assert_equal 3, + response['aggregations']['top_categories']['buckets'][0]['comments']['top_authors']['buckets'].size + assert_equal 'John', + response['aggregations']['top_categories']['buckets'][0]['comments']['top_authors']['buckets'][0]['key'] end end end diff --git a/opensearch-dsl/test/integration/search_aggregation_geo_test.rb b/opensearch-dsl/test/integration/search_aggregation_geo_test.rb index 5ceceb6db..0320ee08a 100644 --- a/opensearch-dsl/test/integration/search_aggregation_geo_test.rb +++ b/opensearch-dsl/test/integration/search_aggregation_geo_test.rb @@ -31,37 +31,36 @@ module Test class GeoAggregationIntegrationTest < ::OpenSearch::Test::IntegrationTestCase include OpenSearch::DSL::Search - context "A geo aggregation" do - + context 'A geo aggregation' do setup do @client.indices.create index: 'venues-test', body: { - mappings: { - properties: { - location: {type: 'geo_point'} - } + mappings: { + properties: { + location: { type: 'geo_point' } } + } } @client.index index: 'venues-test', - body: { name: 'Space', location: "38.886214,1.403889" } + body: { name: 'Space', location: '38.886214,1.403889' } @client.index index: 'venues-test', - body: { name: 'Pacha', location: "38.9184427,1.4433646" } + body: { name: 'Pacha', location: '38.9184427,1.4433646' } @client.index index: 'venues-test', - body: { name: 'Amnesia', location: "38.948045,1.408341" } + body: { name: 'Amnesia', location: '38.948045,1.408341' } @client.index index: 'venues-test', - body: { name: 'Privilege', location: "38.958082,1.408288" } + body: { name: 'Privilege', location: '38.958082,1.408288' } @client.index index: 'venues-test', - body: { name: 'Es Paradis', location: "38.979071,1.307394" } + body: { name: 'Es Paradis', location: '38.979071,1.307394' } @client.indices.refresh index: 'venues-test' end - should "return the geo distances from a location" do + should 'return the geo distances from a location' do response = @client.search index: 'venues-test', size: 0, body: search { aggregation :venue_distances do geo_distance do field :location origin '38.9126352,1.4350621' unit 'km' - ranges [ { to: 1 }, { from: 1, to: 5 }, { from: 5, to: 10 }, { from: 10 } ] + ranges [{ to: 1 }, { from: 1, to: 5 }, { from: 5, to: 10 }, { from: 10 }] aggregation :top_venues do top_hits _source: { include: 'name' } @@ -79,7 +78,7 @@ class GeoAggregationIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 2, result['buckets'][1]['top_venues']['hits']['total']['value'] end - should "return the geohash grid distribution" do + should 'return the geohash grid distribution' do # # See the geohash plot eg. at http://openlocation.org/geohash/geohash-js/ # See the locations visually eg. at http://geohash.org/sncj8h17r2 @@ -103,7 +102,9 @@ class GeoAggregationIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 'sncj8', result['buckets'][0]['key'] assert_equal 2, result['buckets'][0]['doc_count'] - assert_same_elements %w[ Privilege Amnesia ], result['buckets'][0]['top_venues']['hits']['hits'].map { |h| h['_source']['name'] } + assert_same_elements %w[Privilege Amnesia], result['buckets'][0]['top_venues']['hits']['hits'].map { |h| + h['_source']['name'] + } end end end diff --git a/opensearch-dsl/test/integration/search_aggregation_nested_test.rb b/opensearch-dsl/test/integration/search_aggregation_nested_test.rb index bf2e71798..96a4a4131 100644 --- a/opensearch-dsl/test/integration/search_aggregation_nested_test.rb +++ b/opensearch-dsl/test/integration/search_aggregation_nested_test.rb @@ -31,41 +31,40 @@ module Test class NestedAggregationIntegrationTest < ::OpenSearch::Test::IntegrationTestCase include OpenSearch::DSL::Search - context "A nested aggregation" do - + context 'A nested aggregation' do setup do @client.indices.create index: 'products-test', body: { - mappings: { + mappings: { + properties: { + title: { type: 'text' }, + category: { type: 'keyword' }, + offers: { + type: 'nested', properties: { - title: {type: 'text'}, - category: {type: 'keyword'}, - offers: { - type: 'nested', - properties: { - name: {type: 'text'}, - price: {type: 'double'} - } - } + name: { type: 'text' }, + price: { type: 'double' } } + } } + } } @client.index index: 'products-test', body: { title: 'A', category: 'audio', - offers: [ { name: 'A1', price: 100 }, { name: 'A2', price: 120 } ] } + offers: [{ name: 'A1', price: 100 }, { name: 'A2', price: 120 }] } @client.index index: 'products-test', body: { title: 'B', category: 'audio', - offers: [ { name: 'B1', price: 200 }, { name: 'B2', price: 180 } ] } + offers: [{ name: 'B1', price: 200 }, { name: 'B2', price: 180 }] } @client.index index: 'products-test', body: { title: 'C', category: 'video', - offers: [ { name: 'C1', price: 300 }, { name: 'C2', price: 350 } ] } + offers: [{ name: 'C1', price: 300 }, { name: 'C2', price: 350 }] } @client.indices.refresh index: 'products-test' end - should "return the minimal price from offers" do + should 'return the minimal price from offers' do response = @client.search index: 'products-test', body: search { query { match title: 'A' } @@ -82,7 +81,7 @@ class NestedAggregationIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 100, response['aggregations']['offers']['min_price']['value'].to_i end - should "return the top categories for offer price range" do + should 'return the top categories for offer price range' do response = @client.search index: 'products-test', body: search { query do bool do @@ -119,8 +118,10 @@ class NestedAggregationIntegrationTest < ::OpenSearch::Test::IntegrationTestCase }.to_hash assert_equal 2, response['aggregations']['offers']['top_categories']['top_category_per_offer']['buckets'].size - assert_equal 'audio', response['aggregations']['offers']['top_categories']['top_category_per_offer']['buckets'][0]['key'] - assert_equal 'video', response['aggregations']['offers']['top_categories']['top_category_per_offer']['buckets'][1]['key'] + assert_equal 'audio', + response['aggregations']['offers']['top_categories']['top_category_per_offer']['buckets'][0]['key'] + assert_equal 'video', + response['aggregations']['offers']['top_categories']['top_category_per_offer']['buckets'][1]['key'] end end end diff --git a/opensearch-dsl/test/integration/search_aggregations_test.rb b/opensearch-dsl/test/integration/search_aggregations_test.rb index f98c11de3..760f02bd3 100644 --- a/opensearch-dsl/test/integration/search_aggregations_test.rb +++ b/opensearch-dsl/test/integration/search_aggregations_test.rb @@ -31,14 +31,14 @@ module Test class AggregationsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase include OpenSearch::DSL::Search - context "Aggregations integration" do + context 'Aggregations integration' do setup do @client.indices.create index: 'test', body: { - mappings: { - properties: { - tags: {type: 'keyword'} - } + mappings: { + properties: { + tags: { type: 'keyword' } } + } } @client.index index: 'test', id: '1', body: { title: 'A', tags: %w[one], clicks: 5 } @client.index index: 'test', id: '2', body: { title: 'B', tags: %w[one two], clicks: 15 } @@ -46,8 +46,8 @@ class AggregationsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase @client.indices.refresh index: 'test' end - context "with a terms aggregation" do - should "return tag counts" do + context 'with a terms aggregation' do + should 'return tag counts' do response = @client.search index: 'test', body: search { aggregation :tags do terms field: 'tags' @@ -58,7 +58,7 @@ class AggregationsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 'one', response['aggregations']['tags']['buckets'][0]['key'] end - should "return approximate tag counts" do + should 'return approximate tag counts' do response = @client.search index: 'test', body: search { aggregation :tags do cardinality field: 'tags' @@ -68,7 +68,7 @@ class AggregationsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 3, response['aggregations']['tags']['value'] end - should "return tag counts per clicks range as an inner (nested) aggregation" do + should 'return tag counts per clicks range as an inner (nested) aggregation' do response = @client.search index: 'test', body: search { aggregation :clicks do range field: 'clicks' do @@ -87,7 +87,7 @@ class AggregationsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 'one', response['aggregations']['clicks']['buckets']['low']['tags']['buckets'][0]['key'] end - should "define multiple aggregations" do + should 'define multiple aggregations' do response = @client.search index: 'test', body: search { aggregation :clicks do range field: 'clicks' do @@ -127,30 +127,30 @@ class AggregationsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 13, response['aggregations']['avg_clicks']['value'].to_i end - should "define a global aggregation" do + should 'define a global aggregation' do response = @client.search index: 'test', body: search { - query do - bool filter: { terms: { tags: ['two'] } } - end + query do + bool filter: { terms: { tags: ['two'] } } + end - aggregation :avg_clicks do - avg field: 'clicks' - end + aggregation :avg_clicks do + avg field: 'clicks' + end - aggregation :all_documents do - global do - aggregation :avg_clicks do - avg field: 'clicks' - end + aggregation :all_documents do + global do + aggregation :avg_clicks do + avg field: 'clicks' end end + end }.to_hash assert_equal 15, response['aggregations']['avg_clicks']['value'].to_i assert_equal 13, response['aggregations']['all_documents']['avg_clicks']['value'].to_i end - should "return statistics on clicks" do + should 'return statistics on clicks' do response = @client.search index: 'test', body: search { aggregation :stats_clicks do stats field: 'clicks' @@ -168,7 +168,7 @@ class AggregationsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 3, response['aggregations']['value_count']['value'] end - should "return percentiles on clicks" do + should 'return percentiles on clicks' do response = @client.search index: 'test', body: search { aggregation :percentiles do percentiles field: 'clicks' @@ -178,7 +178,7 @@ class AggregationsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 20, response['aggregations']['percentiles']['values']['99.0'].round end - should "return percentile ranks on clicks" do + should 'return percentile ranks on clicks' do response = @client.search index: 'test', body: search { aggregation :percentiles do percentile_ranks field: 'clicks', values: [5] @@ -188,7 +188,7 @@ class AggregationsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 17, response['aggregations']['percentiles']['values']['5.0'].round end - should "return top hits per tag" do + should 'return top hits per tag' do response = @client.search index: 'test', body: search { aggregation :tags do terms do @@ -196,24 +196,25 @@ class AggregationsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase size 5 aggregation :top_hits do - top_hits sort: [ clicks: { order: 'desc' } ], _source: { include: 'title' } + top_hits sort: [clicks: { order: 'desc' }], _source: { include: 'title' } end end end }.to_hash assert_equal 3, response['aggregations']['tags']['buckets'][0]['top_hits']['hits']['hits'].size - assert_equal 'C', response['aggregations']['tags']['buckets'][0]['top_hits']['hits']['hits'][0]['_source']['title'] + assert_equal 'C', + response['aggregations']['tags']['buckets'][0]['top_hits']['hits']['hits'][0]['_source']['title'] end - should "calculate clicks for a tag" do + should 'calculate clicks for a tag' do response = @client.search index: 'test', body: search { aggregation :clicks_for_one do scripted_metric do - init_script "state.transactions = []" + init_script 'state.transactions = []' map_script "if (doc['tags'].value.contains('one')) { state.transactions.add(doc['clicks'].value) }" - combine_script "double sum = 0; for (t in state.transactions) { sum += t } return sum" - reduce_script "double sum = 0; for (a in states) { sum += a } return sum" + combine_script 'double sum = 0; for (t in state.transactions) { sum += t } return sum' + reduce_script 'double sum = 0; for (a in states) { sum += a } return sum' end end }.to_hash @@ -221,7 +222,7 @@ class AggregationsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 40, response['aggregations']['clicks_for_one']['value'] end - should "limit the scope with a filter" do + should 'limit the scope with a filter' do response = @client.search index: 'test', body: search { aggregation :clicks_for_one do filter terms: { tags: ['one'] } do @@ -236,7 +237,7 @@ class AggregationsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase end end - should "return aggregations for multiple filters" do + should 'return aggregations for multiple filters' do response = @client.search index: 'test', body: search { aggregation :avg_clicks_per_tag do filters do @@ -253,7 +254,7 @@ class AggregationsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 15, response['aggregations']['avg_clicks_per_tag']['buckets']['two']['avg']['value'].to_i end - should "return a histogram on clicks" do + should 'return a histogram on clicks' do response = @client.search index: 'test', body: search { aggregation :clicks_histogram do histogram do @@ -268,7 +269,7 @@ class AggregationsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 1, response['aggregations']['clicks_histogram']['buckets'][1]['doc_count'] end - should "return a histogram with empty buckets on clicks" do + should 'return a histogram with empty buckets on clicks' do response = @client.search index: 'test', body: search { aggregation :clicks_histogram do histogram do diff --git a/opensearch-dsl/test/integration/search_filters_test.rb b/opensearch-dsl/test/integration/search_filters_test.rb index 712a13904..bf39ffba8 100644 --- a/opensearch-dsl/test/integration/search_filters_test.rb +++ b/opensearch-dsl/test/integration/search_filters_test.rb @@ -33,7 +33,7 @@ module Test class FiltersIntegrationTest < ::OpenSearch::Test::IntegrationTestCase include OpenSearch::DSL::Search - context "Filters integration" do + context 'Filters integration' do setup do @client.indices.create index: 'test' @client.index index: 'test', id: 1, @@ -88,8 +88,8 @@ class FiltersIntegrationTest < ::OpenSearch::Test::IntegrationTestCase @client.indices.refresh index: 'test' end - context "term filter" do - should "return matching documents" do + context 'term filter' do + should 'return matching documents' do response = @client.search index: 'test', body: search { query do bool do @@ -101,17 +101,17 @@ class FiltersIntegrationTest < ::OpenSearch::Test::IntegrationTestCase }.to_hash assert_equal 4, response['hits']['total']['value'] - assert response['hits']['hits'].all? { |h| h['_source']['color'] == 'red' }, response.inspect + assert response['hits']['hits'].all? { |h| h['_source']['color'] == 'red' }, response.inspect end end - context "terms filter" do - should "return matching documents" do + context 'terms filter' do + should 'return matching documents' do response = @client.search index: 'test', body: search { query do bool do filter do - terms color: ['red', 'grey', 'gold'] + terms color: %w[red grey gold] end end end @@ -121,8 +121,8 @@ class FiltersIntegrationTest < ::OpenSearch::Test::IntegrationTestCase end end - context "bool filter" do - should "return correct documents" do + context 'bool filter' do + should 'return correct documents' do response = @client.search index: 'test', body: search { query do bool do @@ -154,36 +154,36 @@ class FiltersIntegrationTest < ::OpenSearch::Test::IntegrationTestCase end end - context "geographical filters" do + context 'geographical filters' do setup do @client.indices.create index: 'places', body: { - mappings: { - properties: { - location: { - type: 'geo_point' - } - } + mappings: { + properties: { + location: { + type: 'geo_point' + } } + } } @client.index index: 'places', id: 1, body: { name: 'Vyšehrad', - location: '50.064399, 14.420018'} + location: '50.064399, 14.420018' } @client.index index: 'places', id: 2, body: { name: 'Karlštejn', - location: '49.939518, 14.188046'} + location: '49.939518, 14.188046' } @client.indices.refresh index: 'places' end - should "find documents within the bounding box" do + should 'find documents within the bounding box' do response = @client.search index: 'places', body: search { query do bool do filter do geo_bounding_box :location do - top_right "50.1815123678,14.7149200439" - bottom_left "49.9415476869,14.2162566185" + top_right '50.1815123678,14.7149200439' + bottom_left '49.9415476869,14.2162566185' end end end @@ -194,7 +194,7 @@ class FiltersIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 'Vyšehrad', response['hits']['hits'][0]['_source']['name'] end - should "find documents within the distance specified with a hash" do + should 'find documents within the distance specified with a hash' do response = @client.search index: 'places', body: search { query do bool do @@ -209,7 +209,7 @@ class FiltersIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 'Vyšehrad', response['hits']['hits'][0]['_source']['name'] end - should "find documents within the distance specified with a block" do + should 'find documents within the distance specified with a block' do response = @client.search index: 'places', body: search { query do bool do @@ -228,13 +228,13 @@ class FiltersIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 'Vyšehrad', response['hits']['hits'][0]['_source']['name'] end - should "find documents within the geographical distance range" do + should 'find documents within the geographical distance range' do response = @client.search index: 'places', body: search { query do bool do filter do geo_distance location: { lat: '50.090223', lon: '14.399590' }, - distance: '50km' + distance: '50km' end end end @@ -243,7 +243,7 @@ class FiltersIntegrationTest < ::OpenSearch::Test::IntegrationTestCase field :location origin '50.090223,14.399590' unit 'km' - ranges [ { from: 10, to: 50 } ] + ranges [{ from: 10, to: 50 }] aggregation :results do top_hits _source: { include: 'name' } @@ -261,18 +261,18 @@ class FiltersIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 'Karlštejn', bucket['results']['hits']['hits'][0]['_source']['name'] end - should "find documents within the polygon" do + should 'find documents within the polygon' do response = @client.search index: 'places', body: search { query do bool do filter do geo_polygon :location do points [ - [14.2244355,49.9419006], - [14.2244355,50.1774301], - [14.7067869,50.1774301], - [14.7067869,49.9419006], - [14.2244355,49.9419006] + [14.2244355, 49.9419006], + [14.2244355, 50.1774301], + [14.7067869, 50.1774301], + [14.7067869, 49.9419006], + [14.2244355, 49.9419006] ] end end diff --git a/opensearch-dsl/test/integration/search_options_test.rb b/opensearch-dsl/test/integration/search_options_test.rb index ff608b99a..2a78bed1d 100644 --- a/opensearch-dsl/test/integration/search_options_test.rb +++ b/opensearch-dsl/test/integration/search_options_test.rb @@ -31,7 +31,7 @@ module Test class SearchOptionsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase include OpenSearch::DSL::Search - context "Search options" do + context 'Search options' do setup do @client.indices.create index: 'test' @client.index index: 'test', id: '1', body: { title: 'Test' } @@ -39,7 +39,7 @@ class SearchOptionsIntegrationTest < ::OpenSearch::Test::IntegrationTestCase @client.indices.refresh index: 'test' end - should "explain the match" do + should 'explain the match' do response = @client.search index: 'test', body: search { query { match title: 'test' } explain true diff --git a/opensearch-dsl/test/integration/search_query_test.rb b/opensearch-dsl/test/integration/search_query_test.rb index 81eea8e84..be926318f 100644 --- a/opensearch-dsl/test/integration/search_query_test.rb +++ b/opensearch-dsl/test/integration/search_query_test.rb @@ -31,68 +31,67 @@ module Test class QueryIntegrationTest < ::OpenSearch::Test::IntegrationTestCase include OpenSearch::DSL::Search - context "Queries integration" do + context 'Queries integration' do setup do @client.indices.create index: 'test' @client.index index: 'test', id: '1', body: { title: 'Test', tags: ['one'] } - @client.index index: 'test', id: '2', body: { title: 'Rest', tags: ['one', 'two'] } + @client.index index: 'test', id: '2', body: { title: 'Rest', tags: %w[one two] } @client.indices.refresh index: 'test' end - context "for match query" do - should "find the document" do + context 'for match query' do + should 'find the document' do response = @client.search index: 'test', body: search { query { match title: 'test' } }.to_hash assert_equal 1, response['hits']['total']['value'] end end - context "for match_phrase_prefix query" do - should "find the document" do + context 'for match_phrase_prefix query' do + should 'find the document' do response = @client.search index: 'test', body: search { query { match_phrase_prefix title: 'te' } }.to_hash assert_equal 1, response['hits']['total']['value'] end end - context "for query_string query" do - should "find the document" do + context 'for query_string query' do + should 'find the document' do response = @client.search index: 'test', body: search { query { query_string { query 'te*' } } }.to_hash assert_equal 1, response['hits']['total']['value'] end end - context "for the bool query" do - should "find the document" do + context 'for the bool query' do + should 'find the document' do response = @client.search index: 'test', body: search { - query do - bool do - must { terms tags: ['one'] } - should { match title: 'Test' } - end - end - }.to_hash + query do + bool do + must { terms tags: ['one'] } + should { match title: 'Test' } + end + end + }.to_hash assert_equal 2, response['hits']['total']['value'] assert_equal 'Test', response['hits']['hits'][0]['_source']['title'] end - should "find the document with a filter" do + should 'find the document with a filter' do response = @client.search index: 'test', body: search { - query do - bool do - filter { terms tags: ['one'] } - filter { terms tags: ['two'] } - end - end - }.to_hash + query do + bool do + filter { terms tags: ['one'] } + filter { terms tags: ['two'] } + end + end + }.to_hash assert_equal 1, response['hits']['total']['value'] assert_equal 'Rest', response['hits']['hits'][0]['_source']['title'] end end - end end end diff --git a/opensearch-dsl/test/integration/search_size_from_test.rb b/opensearch-dsl/test/integration/search_size_from_test.rb index 843119844..993e7f951 100644 --- a/opensearch-dsl/test/integration/search_size_from_test.rb +++ b/opensearch-dsl/test/integration/search_size_from_test.rb @@ -31,41 +31,41 @@ module Test class SizeIntegrationTest < ::OpenSearch::Test::IntegrationTestCase include OpenSearch::DSL::Search - context "Search results pagination" do - setup do - @client.indices.create index: 'test', body: { - mappings: { properties: { title: { type: 'text', fields: { keyword: { type: 'keyword' } } } } } } + context 'Search results pagination' do + setup do + @client.indices.create index: 'test', body: { + mappings: { properties: { title: { type: 'text', fields: { keyword: { type: 'keyword' } } } } } + } - 25.times { |i| @client.index index: 'test', id: i, body: { title: "Test #{sprintf('%03d', i)}" } } + 25.times { |i| @client.index index: 'test', id: i, body: { title: "Test #{format('%03d', i)}" } } - @client.indices.refresh index: 'test' - end + @client.indices.refresh index: 'test' + end - should "find the correct number of documents" do - response = @client.search index: 'test', body: search { - query { match title: 'test' } - size 15 - }.to_hash + should 'find the correct number of documents' do + response = @client.search index: 'test', body: search { + query { match title: 'test' } + size 15 + }.to_hash - assert_equal 25, response['hits']['total']['value'] - assert_equal 15, response['hits']['hits'].size - end + assert_equal 25, response['hits']['total']['value'] + assert_equal 15, response['hits']['hits'].size + end - should "move the offset" do - response = @client.search index: 'test', body: search { - query { match(:title) { query 'test' } } - size 5 - from 5 - sort { by 'title.keyword' } - }.to_hash + should 'move the offset' do + response = @client.search index: 'test', body: search { + query { match(:title) { query 'test' } } + size 5 + from 5 + sort { by 'title.keyword' } + }.to_hash - assert_equal 25, response['hits']['total']['value'] - assert_equal 5, response['hits']['hits'].size - assert_equal 'Test 005', response['hits']['hits'][0]['_source']['title'] - assert_equal 'Test 009', response['hits']['hits'][4]['_source']['title'] - end + assert_equal 25, response['hits']['total']['value'] + assert_equal 5, response['hits']['hits'].size + assert_equal 'Test 005', response['hits']['hits'][0]['_source']['title'] + assert_equal 'Test 009', response['hits']['hits'][4]['_source']['title'] end - + end end end end diff --git a/opensearch-dsl/test/integration/search_sort_test.rb b/opensearch-dsl/test/integration/search_sort_test.rb index 43b74a4bc..5a0d94ac1 100644 --- a/opensearch-dsl/test/integration/search_sort_test.rb +++ b/opensearch-dsl/test/integration/search_sort_test.rb @@ -31,27 +31,26 @@ module Test class SortingIntegrationTest < ::OpenSearch::Test::IntegrationTestCase include OpenSearch::DSL::Search - context "Sorting integration" do + context 'Sorting integration' do setup do @client.indices.create index: 'test' @client.index index: 'test', id: '1', body: { tags: ['one'], clicks: 15 } - @client.index index: 'test', id: '2', body: { tags: ['one', 'two'], clicks: 5 } - @client.index index: 'test', id: '3', body: { tags: ['one', 'three'], clicks: 20 } + @client.index index: 'test', id: '2', body: { tags: %w[one two], clicks: 5 } + @client.index index: 'test', id: '3', body: { tags: %w[one three], clicks: 20 } @client.indices.refresh index: 'test' end - context "sorting by clicks" do - should "return documents in order" do + context 'sorting by clicks' do + should 'return documents in order' do response = @client.search index: 'test', body: search { sort do by :clicks, order: 'desc' end }.to_hash - assert_same_elements ['3', '1', '2'], response['hits']['hits'].map { |d| d['_id'] } + assert_same_elements %w[3 1 2], response['hits']['hits'].map { |d| d['_id'] } end end - end end end diff --git a/opensearch-dsl/test/integration/search_suggest_test.rb b/opensearch-dsl/test/integration/search_suggest_test.rb index 0fdff4e82..080f35db2 100644 --- a/opensearch-dsl/test/integration/search_suggest_test.rb +++ b/opensearch-dsl/test/integration/search_suggest_test.rb @@ -33,48 +33,48 @@ module Test class SuggestIntegrationTest < ::OpenSearch::Test::IntegrationTestCase include OpenSearch::DSL::Search - context "Suggest integration" do + context 'Suggest integration' do setup do @client.indices.create index: 'test', body: { - mappings: { + mappings: { + properties: { + title: { type: 'text' }, + suggest: { + type: 'object', properties: { - title: {type: 'text'}, - suggest: { - type: 'object', - properties: { - title: {type: 'completion'}, - payload: {type: 'object', enabled: false} - } - } + title: { type: 'completion' }, + payload: { type: 'object', enabled: false } } + } } + } } @client.index index: 'test', id: '1', body: { title: 'One', suggest: { - title: { input: ['one', 'uno', 'jedna'] }, + title: { input: %w[one uno jedna] }, payload: { id: '1' } } } @client.index index: 'test', id: '2', body: { title: 'Two', suggest: { - title: { input: ['two', 'due', 'dvě'] }, + title: { input: %w[two due dvě] }, payload: { id: '2' } } } @client.index index: 'test', id: '3', body: { title: 'Three', suggest: { - title: { input: ['three', 'tres', 'tři'] }, + title: { input: %w[three tres tři] }, payload: { id: '3' } } } @client.indices.refresh index: 'test' end - should "return suggestions" do + should 'return suggestions' do s = search do suggest :title, text: 't', completion: { field: 'suggest.title' } end @@ -83,10 +83,12 @@ class SuggestIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 2, response['suggest']['title'][0]['options'].size - assert_same_elements %w[2 3], response['suggest']['title'][0]['options'].map { |d| d['_source']['suggest']['payload']['id'] } + assert_same_elements %w[2 3], response['suggest']['title'][0]['options'].map { |d| + d['_source']['suggest']['payload']['id'] + } end - should "return a single suggestion" do + should 'return a single suggestion' do s = search do suggest :title, text: 'th', completion: { field: 'suggest.title' } end @@ -95,7 +97,9 @@ class SuggestIntegrationTest < ::OpenSearch::Test::IntegrationTestCase assert_equal 1, response['suggest']['title'][0]['options'].size - assert_same_elements %w[3], response['suggest']['title'][0]['options'].map { |d| d['_source']['suggest']['payload']['id'] } + assert_same_elements %w[3], response['suggest']['title'][0]['options'].map { |d| + d['_source']['suggest']['payload']['id'] + } end end end diff --git a/opensearch-dsl/test/integration/search_test.rb b/opensearch-dsl/test/integration/search_test.rb index c47c1ecd0..96a1dc75a 100644 --- a/opensearch-dsl/test/integration/search_test.rb +++ b/opensearch-dsl/test/integration/search_test.rb @@ -39,7 +39,7 @@ def initialize(q) end def tags - %w[ one two ] + %w[one two] end def search_definition @@ -58,23 +58,22 @@ def search_definition end end - context "The Search class" do + context 'The Search class' do setup do @client.indices.create index: 'test' @client.index index: 'test', id: '1', body: { title: 'Test', tags: ['one'] } - @client.index index: 'test', id: '2', body: { title: 'Test', tags: ['one', 'two'] } + @client.index index: 'test', id: '2', body: { title: 'Test', tags: %w[one two] } @client.index index: 'test', id: '3', body: { title: 'Test', tags: ['three'] } @client.indices.refresh index: 'test' end - - should "have access to the calling context" do + should 'have access to the calling context' do s = MySearch.new('test') response = @client.search index: 'test', body: s.search_definition.to_hash assert_equal 2, response['hits']['total']['value'] assert_equal 'Test', response['hits']['hits'][0]['_source']['title'] - assert_same_elements ['1', '2'], response['hits']['hits'].map { |d| d['_id'] } + assert_same_elements %w[1 2], response['hits']['hits'].map { |d| d['_id'] } end end end diff --git a/opensearch-dsl/test/test_helper.rb b/opensearch-dsl/test/test_helper.rb index a258603c9..d1aae250e 100644 --- a/opensearch-dsl/test/test_helper.rb +++ b/opensearch-dsl/test/test_helper.rb @@ -24,21 +24,21 @@ # specific language governing permissions and limitations # under the License. -OPENSEARCH_HOSTS = if hosts = ENV['TEST_OPENSEARCH_SERVER'] || ENV['OPENSEARCH_HOSTS'] - hosts.split(',').map do |host| - /(http\:\/\/)?(\S+)/.match(host)[2] - end - else - ['localhost:9200'] - end.freeze +OPENSEARCH_HOSTS = if hosts = ENV.fetch('TEST_OPENSEARCH_SERVER', nil) || ENV.fetch('OPENSEARCH_HOSTS', nil) + hosts.split(',').map do |host| + %r{(http://)?(\S+)}.match(host)[2] + end + else + ['localhost:9200'] + end.freeze TEST_HOST, TEST_PORT = OPENSEARCH_HOSTS.first.split(':') if OPENSEARCH_HOSTS JRUBY = defined?(JRUBY_VERSION) -if ENV['COVERAGE'] || ENV['CI'] +if ENV.fetch('COVERAGE', nil) || ENV.fetch('CI', nil) require 'simplecov' - SimpleCov.start { add_filter "/test|test_" } + SimpleCov.start { add_filter '/test|test_' } end require 'minitest/autorun' @@ -60,26 +60,26 @@ def assert_nothing_raised(*) class UnitTestCase < ::Minitest::Test include Assertions - alias_method :assert_not_nil, :refute_nil - alias_method :assert_raise, :assert_raises + alias assert_not_nil refute_nil + alias assert_raise assert_raises end class IntegrationTestCase < ::Minitest::Test include Assertions - alias_method :assert_not_nil, :refute_nil - alias_method :assert_raise, :assert_raises + alias assert_not_nil refute_nil + alias assert_raise assert_raises def setup - @port = (ENV['TEST_CLUSTER_PORT'] || 9250).to_i + @port = (ENV.fetch('TEST_CLUSTER_PORT', nil) || 9250).to_i - @logger = Logger.new(STDERR) - @logger.formatter = proc do |severity, datetime, progname, msg| + @logger = Logger.new(STDERR) + @logger.formatter = proc do |severity, _datetime, _progname, msg| color = case severity - when /INFO/ then :green - when /ERROR|WARN|FATAL/ then :red - when /DEBUG/ then :cyan - else :white - end + when /INFO/ then :green + when /ERROR|WARN|FATAL/ then :red + when /DEBUG/ then :cyan + else :white + end ANSI.ansi(severity[0] + ' ', color, :faint) + ANSI.ansi(msg, :white, :faint) + "\n" end diff --git a/opensearch-dsl/test/unit/dsl_test.rb b/opensearch-dsl/test/unit/dsl_test.rb index 4bb0e6343..1c1d24a12 100644 --- a/opensearch-dsl/test/unit/dsl_test.rb +++ b/opensearch-dsl/test/unit/dsl_test.rb @@ -29,12 +29,12 @@ module OpenSearch module Test class DSLTest < ::OpenSearch::Test::UnitTestCase - context "The DSL" do + context 'The DSL' do class DummyDSLReceiver include OpenSearch::DSL end - should "include the module in receiver" do + should 'include the module in receiver' do assert_contains DummyDSLReceiver.included_modules, OpenSearch::DSL assert_contains DummyDSLReceiver.included_modules, OpenSearch::DSL::Search end diff --git a/opensearch-dsl/test/unit/search_aggregation_test.rb b/opensearch-dsl/test/unit/search_aggregation_test.rb index c7d84eaac..fcbe1f031 100644 --- a/opensearch-dsl/test/unit/search_aggregation_test.rb +++ b/opensearch-dsl/test/unit/search_aggregation_test.rb @@ -31,68 +31,66 @@ module Test class SearchAggregationTest < ::OpenSearch::Test::UnitTestCase subject { OpenSearch::DSL::Search::Aggregation.new } - context "Search Aggregation" do - - should "be serializable to a Hash" do - assert_equal( {}, subject.to_hash ) + context 'Search Aggregation' do + should 'be serializable to a Hash' do + assert_equal({}, subject.to_hash) subject = OpenSearch::DSL::Search::Aggregation.new subject.instance_variable_set(:@value, { foo: 'bar' }) - assert_equal( { foo: 'bar' }, subject.to_hash ) + assert_equal({ foo: 'bar' }, subject.to_hash) end - should "evaluate the block and return itself" do - block = Proc.new { 1+1 } - subject = OpenSearch::DSL::Search::Aggregation.new &block + should 'evaluate the block and return itself' do + block = proc { 1 + 1 } + subject = OpenSearch::DSL::Search::Aggregation.new(&block) subject.expects(:instance_eval) assert_instance_of OpenSearch::DSL::Search::Aggregation, subject.call end - should "call the block and return itself" do - block = Proc.new { |s| 1+1 } - subject = OpenSearch::DSL::Search::Aggregation.new &block + should 'call the block and return itself' do + block = proc { |_s| 1 + 1 } + subject = OpenSearch::DSL::Search::Aggregation.new(&block) block.expects(:call) assert_instance_of OpenSearch::DSL::Search::Aggregation, subject.call end - should "define the value with DSL methods" do + should 'define the value with DSL methods' do assert_nothing_raised do subject.terms field: 'foo' assert_instance_of Hash, subject.to_hash - assert_equal( { terms: { field: 'foo' } }, subject.to_hash ) + assert_equal({ terms: { field: 'foo' } }, subject.to_hash) end end - should "raise an exception for unknown DSL method" do + should 'raise an exception for unknown DSL method' do assert_raise(NoMethodError) { subject.foofoo } end - should "return the aggregations" do + should 'return the aggregations' do subject.expects(:call) subject.instance_variable_set(:@value, mock(aggregations: { foo: 'bar' })) subject.aggregations end - should "define a nested aggregation" do + should 'define a nested aggregation' do subject.instance_variable_set(:@value, mock(aggregation: true)) - subject.aggregation(:foo) { 1+1 } + subject.aggregation(:foo) { 1 + 1 } end - should "return a non-hashy value directly" do + should 'return a non-hashy value directly' do subject.instance_variable_set(:@value, 'FOO') assert_equal 'FOO', subject.to_hash end - should "return an empty Hash when it has no value set" do + should 'return an empty Hash when it has no value set' do subject.instance_variable_set(:@value, nil) assert_equal({}, subject.to_hash) end end - end end end diff --git a/opensearch-dsl/test/unit/search_base_aggregation_component_test.rb b/opensearch-dsl/test/unit/search_base_aggregation_component_test.rb index 0ada657a7..976efd285 100644 --- a/opensearch-dsl/test/unit/search_base_aggregation_component_test.rb +++ b/opensearch-dsl/test/unit/search_base_aggregation_component_test.rb @@ -29,8 +29,7 @@ module OpenSearch module Test class BaseAggregationComponentTest < ::OpenSearch::Test::UnitTestCase - context "BaseAggregationComponent" do - + context 'BaseAggregationComponent' do class DummyAggregationComponent include ::OpenSearch::DSL::Search::BaseAggregationComponent end @@ -41,23 +40,23 @@ class ::OpenSearch::DSL::Search::Aggregations::Dummy subject { DummyAggregationComponent.new } - should "return an instance of the aggregation by name" do + should 'return an instance of the aggregation by name' do assert_instance_of ::OpenSearch::DSL::Search::Aggregations::Dummy, subject.dummy end - should "raise an exception when unknown aggregation is called" do + should 'raise an exception when unknown aggregation is called' do assert_raise(NoMethodError) { subject.foobar } end - should "add a nested aggregation" do + should 'add a nested aggregation' do subject.aggregation :inner do dummy field: 'foo' end - assert ! subject.aggregations.empty?, "#{subject.aggregations.inspect} is empty" + assert !subject.aggregations.empty?, "#{subject.aggregations.inspect} is empty" assert_instance_of OpenSearch::DSL::Search::Aggregation, subject.aggregations[:inner] - assert_equal( {:dummy=>{:field=>"foo"}}, subject.aggregations[:inner].to_hash ) + assert_equal({ dummy: { field: 'foo' } }, subject.aggregations[:inner].to_hash) assert_equal 'foo', subject.to_hash[:aggregations][:inner][:dummy][:field] end diff --git a/opensearch-dsl/test/unit/search_base_component_test.rb b/opensearch-dsl/test/unit/search_base_component_test.rb index cfe4a914e..6b5290226 100644 --- a/opensearch-dsl/test/unit/search_base_component_test.rb +++ b/opensearch-dsl/test/unit/search_base_component_test.rb @@ -29,8 +29,7 @@ module OpenSearch module Test class BaseComponentTest < ::OpenSearch::Test::UnitTestCase - context "BaseComponent" do - + context 'BaseComponent' do class DummyComponent include OpenSearch::DSL::Search::BaseComponent end @@ -50,15 +49,15 @@ class DummyCompoundFilter subject { DummyComponent.new :foo } - should "have a name" do + should 'have a name' do assert_equal :dummy_component, DummyComponent.new.name end - should "have a custom name" do + should 'have a custom name' do assert_equal :foo, DummyComponentWithAName.new.name end - should "allow to set a name" do + should 'allow to set a name' do DummyComponentWithNewName.name :foo assert_equal :foo, DummyComponentWithNewName.new.name assert_equal :foo, DummyComponentWithNewName.name @@ -68,16 +67,16 @@ class DummyCompoundFilter assert_equal :bar, DummyComponentWithNewName.new.name end - should "initialize the hash" do + should 'initialize the hash' do assert_instance_of Hash, subject.to_hash end - should "have an empty Hash as args by default" do + should 'have an empty Hash as args by default' do subject = DummyComponentWithNewName.new assert_equal({}, subject.instance_variable_get(:@args)) end - should "have an option method with args" do + should 'have an option method with args' do class DummyComponentWithOptionMethod include OpenSearch::DSL::Search::BaseComponent option_method :bar @@ -90,7 +89,7 @@ class DummyComponentWithOptionMethod assert_equal({ dummy_component_with_option_method: { foo: { bar: 'BAM' } } }, subject.to_hash) end - should "keep track of option methods" do + should 'keep track of option methods' do class DummyComponentWithCustomOptionMethod include OpenSearch::DSL::Search::BaseComponent option_method :foo @@ -100,7 +99,7 @@ class DummyComponentWithCustomOptionMethod assert_includes subject.option_methods, :foo end - should "have an option method without args" do + should 'have an option method without args' do class DummyComponentWithOptionMethod include OpenSearch::DSL::Search::BaseComponent option_method :bar @@ -113,10 +112,10 @@ class DummyComponentWithOptionMethod assert_equal({ dummy_component_with_option_method: { bar: 'BAM' } }, subject.to_hash) end - should "define a custom option method" do + should 'define a custom option method' do class DummyComponentWithCustomOptionMethod include OpenSearch::DSL::Search::BaseComponent - option_method :bar, lambda { |*args| @hash = { :foo => 'bar' } } + option_method :bar, ->(*_args) { @hash = { foo: 'bar' } } end subject = DummyComponentWithCustomOptionMethod.new @@ -125,7 +124,7 @@ class DummyComponentWithCustomOptionMethod assert_equal 'bar', subject.instance_variable_get(:@hash)[:foo] end - should "execute the passed block" do + should 'execute the passed block' do subject = DummyComponent.new(:foo) { @foo = 'BAR' } assert_respond_to subject, :call @@ -133,33 +132,32 @@ class DummyComponentWithCustomOptionMethod assert_equal 'BAR', subject.instance_variable_get(:@foo) end - should "respond to empty?" do + should 'respond to empty?' do assert DummyComponent.new.empty? assert DummyComponent.new(:foo).empty? subject = DummyComponent.new(:foo) { @hash = { foo: 'bar' } } - assert ! subject.empty? + assert !subject.empty? end - context "to_hash conversion" do - - should "build the hash with the block with args" do + context 'to_hash conversion' do + should 'build the hash with the block with args' do subject = DummyComponent.new :foo do @hash[:dummy_component][:foo].update moo: 'xoo' end - assert_equal({dummy_component: { foo: { moo: 'xoo' } } }, subject.to_hash ) + assert_equal({ dummy_component: { foo: { moo: 'xoo' } } }, subject.to_hash) end - should "build the hash with the block without args" do + should 'build the hash with the block without args' do subject = DummyComponent.new do @hash[:dummy_component].update moo: 'xoo' end - assert_equal({dummy_component: { moo: 'xoo' } }, subject.to_hash ) + assert_equal({ dummy_component: { moo: 'xoo' } }, subject.to_hash) end - should "build the hash with the option method" do + should 'build the hash with the option method' do class DummyComponentWithOptionMethod include OpenSearch::DSL::Search::BaseComponent option_method :foo @@ -172,13 +170,13 @@ class DummyComponentWithOptionMethod assert_equal({ dummy_component_with_option_method: { foo: 'bar' } }, subject.to_hash) end - should "build the hash with the passed args" do + should 'build the hash with the passed args' do subject = DummyComponent.new foo: 'bar' assert_equal({ dummy_component: { foo: 'bar' } }, subject.to_hash) end - should "merge the top-level options to the hash" do + should 'merge the top-level options to the hash' do class DummyComponentWithOptionMethod include OpenSearch::DSL::Search::BaseComponent option_method :bar @@ -191,7 +189,7 @@ class DummyComponentWithOptionMethod assert_equal({ dummy_component_with_option_method: { xoo: 'X', foo: { bar: 'B' } } }, subject.to_hash) end - should "return the already built hash" do + should 'return the already built hash' do subject = DummyComponent.new subject.instance_variable_set(:@hash, { foo: 'bar' }) @@ -199,10 +197,10 @@ class DummyComponentWithOptionMethod end end - context "compound filter" do + context 'compound filter' do subject { DummyCompoundFilter.new } - should "raise an exception for unknown DSL method" do + should 'raise an exception for unknown DSL method' do assert_raise(NoMethodError) { subject.foofoo } end end diff --git a/opensearch-dsl/test/unit/search_filter_test.rb b/opensearch-dsl/test/unit/search_filter_test.rb index 6cf864fbf..343fe6fb3 100644 --- a/opensearch-dsl/test/unit/search_filter_test.rb +++ b/opensearch-dsl/test/unit/search_filter_test.rb @@ -31,41 +31,40 @@ module Test class SearchFilterTest < ::OpenSearch::Test::UnitTestCase subject { OpenSearch::DSL::Search::Filter.new } - context "Search Filter" do - - should "be serializable to a Hash" do - assert_equal( {}, subject.to_hash ) + context 'Search Filter' do + should 'be serializable to a Hash' do + assert_equal({}, subject.to_hash) subject = OpenSearch::DSL::Search::Filter.new subject.instance_variable_set(:@value, { foo: 'bar' }) - assert_equal( { foo: 'bar' }, subject.to_hash ) + assert_equal({ foo: 'bar' }, subject.to_hash) end - should "evaluate the block and return itself" do - block = Proc.new { 1+1 } - subject = OpenSearch::DSL::Search::Filter.new &block + should 'evaluate the block and return itself' do + block = proc { 1 + 1 } + subject = OpenSearch::DSL::Search::Filter.new(&block) subject.expects(:instance_eval) assert_instance_of OpenSearch::DSL::Search::Filter, subject.call end - should "call the block and return itself" do - block = Proc.new { |s| 1+1 } - subject = OpenSearch::DSL::Search::Filter.new &block + should 'call the block and return itself' do + block = proc { |_s| 1 + 1 } + subject = OpenSearch::DSL::Search::Filter.new(&block) block.expects(:call) assert_instance_of OpenSearch::DSL::Search::Filter, subject.call end - should "define the value with filter methods" do + should 'define the value with filter methods' do assert_nothing_raised do subject.term foo: 'bar' assert_instance_of Hash, subject.to_hash - assert_equal( { term: { foo: 'bar' } }, subject.to_hash ) + assert_equal({ term: { foo: 'bar' } }, subject.to_hash) end end - should "redefine the value with filter methods" do + should 'redefine the value with filter methods' do assert_nothing_raised do subject.term foo: 'bar' subject.term foo: 'bam' @@ -76,12 +75,10 @@ class SearchFilterTest < ::OpenSearch::Test::UnitTestCase end end - should "raise an exception for unknown filter" do + should 'raise an exception for unknown filter' do assert_raise(NoMethodError) { subject.foofoo } end - end - end end end diff --git a/opensearch-dsl/test/unit/search_highlight_test.rb b/opensearch-dsl/test/unit/search_highlight_test.rb index 16a6e5623..49c2bb0e7 100644 --- a/opensearch-dsl/test/unit/search_highlight_test.rb +++ b/opensearch-dsl/test/unit/search_highlight_test.rb @@ -29,69 +29,69 @@ module OpenSearch module Test class HighlightTest < ::OpenSearch::Test::UnitTestCase - context "Search highlight" do + context 'Search highlight' do subject { OpenSearch::DSL::Search::Highlight.new } - should "take a Hash" do - subject = OpenSearch::DSL::Search::Highlight.new fields: { 'foo' => {} }, pre_tags: ['*'], post_tags: ['*'] + should 'take a Hash' do + subject = OpenSearch::DSL::Search::Highlight.new fields: { 'foo' => {} }, pre_tags: ['*'], post_tags: ['*'] assert_equal({ fields: { 'foo' => {} }, pre_tags: ['*'], post_tags: ['*'] }, subject.to_hash) end - should "encode fields as an array" do - subject.fields ['foo', 'bar'] + should 'encode fields as an array' do + subject.fields %w[foo bar] assert_equal({ fields: { foo: {}, bar: {} } }, subject.to_hash) end - should "encode fields as a Hash" do + should 'encode fields as a Hash' do subject.fields foo: { bar: 1 }, xoo: { bar: 2 } assert_equal({ fields: { foo: { bar: 1 }, xoo: { bar: 2 } } }, subject.to_hash) end - should "encode a field" do + should 'encode a field' do subject.field 'foo' assert_equal({ fields: { foo: {} } }, subject.to_hash) end - should "be additive on multiple calls" do - subject.fields ['foo', 'bar'] + should 'be additive on multiple calls' do + subject.fields %w[foo bar] subject.field 'bam' subject.field 'baz', { xoo: 10 } assert_equal({ fields: { foo: {}, bar: {}, bam: {}, baz: { xoo: 10 } } }, subject.to_hash) end - should "encode pre_tags" do + should 'encode pre_tags' do subject.pre_tags '*' assert_equal({ pre_tags: ['*'] }, subject.to_hash) end - should "encode post_tags" do + should 'encode post_tags' do subject.post_tags '*' assert_equal({ post_tags: ['*'] }, subject.to_hash) end - should "encode pre_tags as an array" do + should 'encode pre_tags as an array' do subject.pre_tags ['*', '**'] assert_equal({ pre_tags: ['*', '**'] }, subject.to_hash) end - should "encode post_tags as an array" do + should 'encode post_tags as an array' do subject.post_tags ['*', '**'] assert_equal({ post_tags: ['*', '**'] }, subject.to_hash) end - should "encode the encoder option" do + should 'encode the encoder option' do subject.encoder 'foo' assert_equal({ encoder: 'foo' }, subject.to_hash) end - should "encode the tags_schema option" do + should 'encode the tags_schema option' do subject.tags_schema 'foo' assert_equal({ tags_schema: 'foo' }, subject.to_hash) end - should "combine the options" do - subject.fields ['foo', 'bar'] + should 'combine the options' do + subject.fields %w[foo bar] subject.field 'bam' subject.pre_tags '*' subject.post_tags '*' diff --git a/opensearch-dsl/test/unit/search_options_test.rb b/opensearch-dsl/test/unit/search_options_test.rb index 1b2b95a45..fa8945d88 100644 --- a/opensearch-dsl/test/unit/search_options_test.rb +++ b/opensearch-dsl/test/unit/search_options_test.rb @@ -31,82 +31,82 @@ module Test class SearchOptionsTest < ::OpenSearch::Test::UnitTestCase subject { OpenSearch::DSL::Search::Options.new } - context "Search options" do - should "combine different options" do + context 'Search options' do + should 'combine different options' do subject.version true subject.min_score 0.5 - assert_equal({version: true, min_score: 0.5}, subject.to_hash) + assert_equal({ version: true, min_score: 0.5 }, subject.to_hash) end - should "encode _source" do + should 'encode _source' do subject._source false - assert_equal( { _source: false }, subject.to_hash ) + assert_equal({ _source: false }, subject.to_hash) subject._source 'foo.*' - assert_equal( { _source: 'foo.*' }, subject.to_hash ) + assert_equal({ _source: 'foo.*' }, subject.to_hash) - subject._source ['foo', 'bar'] - assert_equal( { _source: ['foo', 'bar'] }, subject.to_hash ) + subject._source %w[foo bar] + assert_equal({ _source: %w[foo bar] }, subject.to_hash) subject._source include: ['foo.*'], exclude: ['bar.*'] - assert_equal( { _source: { include: ['foo.*'], exclude: ['bar.*'] } }, subject.to_hash ) + assert_equal({ _source: { include: ['foo.*'], exclude: ['bar.*'] } }, subject.to_hash) subject.source false - assert_equal( { _source: false }, subject.to_hash ) + assert_equal({ _source: false }, subject.to_hash) end - should "encode fields" do + should 'encode fields' do subject.fields ['foo'] - assert_equal( { fields: ['foo'] }, subject.to_hash ) + assert_equal({ fields: ['foo'] }, subject.to_hash) end - should "encode script_fields" do + should 'encode script_fields' do subject.script_fields ['foo'] - assert_equal( { script_fields: ['foo'] }, subject.to_hash ) + assert_equal({ script_fields: ['foo'] }, subject.to_hash) end - should "encode fielddata_fields" do + should 'encode fielddata_fields' do subject.fielddata_fields ['foo'] - assert_equal( { fielddata_fields: ['foo'] }, subject.to_hash ) + assert_equal({ fielddata_fields: ['foo'] }, subject.to_hash) end - should "encode rescore" do + should 'encode rescore' do subject.rescore foo: 'bar' - assert_equal( { rescore: { foo: 'bar' } }, subject.to_hash ) + assert_equal({ rescore: { foo: 'bar' } }, subject.to_hash) end - should "encode explain" do + should 'encode explain' do subject.explain true - assert_equal( { explain: true }, subject.to_hash ) + assert_equal({ explain: true }, subject.to_hash) end - should "encode version" do + should 'encode version' do subject.version true - assert_equal( { version: true }, subject.to_hash ) + assert_equal({ version: true }, subject.to_hash) end - should "encode track_total_hits" do + should 'encode track_total_hits' do subject.track_total_hits 123 - assert_equal( { track_total_hits: 123 }, subject.to_hash ) + assert_equal({ track_total_hits: 123 }, subject.to_hash) subject.track_total_hits true - assert_equal( { track_total_hits: true }, subject.to_hash ) + assert_equal({ track_total_hits: true }, subject.to_hash) end - should "encode indices_boost" do + should 'encode indices_boost' do subject.indices_boost foo: 'bar' - assert_equal( { indices_boost: { foo: 'bar' } }, subject.to_hash ) + assert_equal({ indices_boost: { foo: 'bar' } }, subject.to_hash) end - should "encode track_scores" do + should 'encode track_scores' do subject.track_scores true - assert_equal( { track_scores: true }, subject.to_hash ) + assert_equal({ track_scores: true }, subject.to_hash) end - should "encode min_score" do + should 'encode min_score' do subject.min_score 0.5 - assert_equal( { min_score: 0.5 }, subject.to_hash ) + assert_equal({ min_score: 0.5 }, subject.to_hash) end end end diff --git a/opensearch-dsl/test/unit/search_query_test.rb b/opensearch-dsl/test/unit/search_query_test.rb index 010859ac5..24c4e5ec4 100644 --- a/opensearch-dsl/test/unit/search_query_test.rb +++ b/opensearch-dsl/test/unit/search_query_test.rb @@ -31,41 +31,40 @@ module Test class SearchQueryTest < ::OpenSearch::Test::UnitTestCase subject { OpenSearch::DSL::Search::Query.new } - context "Search Query" do - - should "be serializable to a Hash" do - assert_equal( {}, subject.to_hash ) + context 'Search Query' do + should 'be serializable to a Hash' do + assert_equal({}, subject.to_hash) subject = OpenSearch::DSL::Search::Query.new subject.instance_variable_set(:@value, {}) - assert_equal( {}, subject.to_hash ) + assert_equal({}, subject.to_hash) end - should "evaluate the block and return itself" do - block = Proc.new { 1+1 } - subject = OpenSearch::DSL::Search::Query.new &block + should 'evaluate the block and return itself' do + block = proc { 1 + 1 } + subject = OpenSearch::DSL::Search::Query.new(&block) subject.expects(:instance_eval) assert_instance_of OpenSearch::DSL::Search::Query, subject.call end - should "call the block and return itself" do - block = Proc.new { |s| 1+1 } - subject = OpenSearch::DSL::Search::Query.new &block + should 'call the block and return itself' do + block = proc { |_s| 1 + 1 } + subject = OpenSearch::DSL::Search::Query.new(&block) block.expects(:call) assert_instance_of OpenSearch::DSL::Search::Query, subject.call end - should "define the value with query methods" do + should 'define the value with query methods' do assert_nothing_raised do subject.match foo: 'bar' assert_instance_of Hash, subject.to_hash - assert_equal( { match: { foo: 'bar' } }, subject.to_hash ) + assert_equal({ match: { foo: 'bar' } }, subject.to_hash) end end - should "redefine the value with query methods" do + should 'redefine the value with query methods' do assert_nothing_raised do subject.match foo: 'bar' subject.match foo: 'bam' @@ -76,16 +75,14 @@ class SearchQueryTest < ::OpenSearch::Test::UnitTestCase end end - should "have the query methods" do + should 'have the query methods' do assert_nothing_raised { subject.match foo: 'bar' } end - should "raise an exception for unknown query" do + should 'raise an exception for unknown query' do assert_raise(NoMethodError) { subject.foofoo } end - end - end end end diff --git a/opensearch-dsl/test/unit/search_size_from_test.rb b/opensearch-dsl/test/unit/search_size_from_test.rb index dbae296d7..9538766a1 100644 --- a/opensearch-dsl/test/unit/search_size_from_test.rb +++ b/opensearch-dsl/test/unit/search_size_from_test.rb @@ -29,23 +29,22 @@ module OpenSearch module Test class SearchSizeTest < ::OpenSearch::Test::UnitTestCase - context "Search pagination" do - - should "encode the size parameter" do + context 'Search pagination' do + should 'encode the size parameter' do subject = OpenSearch::DSL::Search::Search.new do size 5 end - assert_equal( { size: 5 }, subject.to_hash ) + assert_equal({ size: 5 }, subject.to_hash) end - should "encode the from parameter" do + should 'encode the from parameter' do subject = OpenSearch::DSL::Search::Search.new do from 5 end - assert_equal( { from: 5 }, subject.to_hash ) + assert_equal({ from: 5 }, subject.to_hash) end - should "have getter methods" do + should 'have getter methods' do subject = OpenSearch::DSL::Search::Search.new assert_nil subject.size assert_nil subject.from @@ -55,13 +54,13 @@ class SearchSizeTest < ::OpenSearch::Test::UnitTestCase assert_equal 5, subject.from end - should "have setter methods" do + should 'have setter methods' do subject = OpenSearch::DSL::Search::Search.new subject.size = 5 subject.from = 5 assert_equal 5, subject.size assert_equal 5, subject.from - assert_equal( { size: 5, from: 5 }, subject.to_hash ) + assert_equal({ size: 5, from: 5 }, subject.to_hash) end end end diff --git a/opensearch-dsl/test/unit/search_sort_test.rb b/opensearch-dsl/test/unit/search_sort_test.rb index a12507f6e..203ac9302 100644 --- a/opensearch-dsl/test/unit/search_sort_test.rb +++ b/opensearch-dsl/test/unit/search_sort_test.rb @@ -31,24 +31,23 @@ module Test class SearchSortTest < ::OpenSearch::Test::UnitTestCase subject { OpenSearch::DSL::Search::Sort.new } - context "Search sort" do - - should "add a single field" do + context 'Search sort' do + should 'add a single field' do subject = OpenSearch::DSL::Search::Sort.new :foo - assert_equal( [:foo], subject.to_hash ) + assert_equal([:foo], subject.to_hash) end - should "add multiple fields" do - subject = OpenSearch::DSL::Search::Sort.new [:foo, :bar] - assert_equal( [:foo, :bar], subject.to_hash ) + should 'add multiple fields' do + subject = OpenSearch::DSL::Search::Sort.new %i[foo bar] + assert_equal(%i[foo bar], subject.to_hash) end - should "add a field with options" do + should 'add a field with options' do subject = OpenSearch::DSL::Search::Sort.new foo: { order: 'desc', mode: 'avg' } - assert_equal( [ { foo: { order: 'desc', mode: 'avg' } } ], subject.to_hash ) + assert_equal([{ foo: { order: 'desc', mode: 'avg' } }], subject.to_hash) end - should "add fields with the DSL method" do + should 'add fields with the DSL method' do subject = OpenSearch::DSL::Search::Sort.new do by :foo by :bar, order: 'desc' @@ -57,27 +56,28 @@ class SearchSortTest < ::OpenSearch::Test::UnitTestCase assert_equal( [ :foo, - { bar: { order: 'desc' } }, - ], subject.to_hash ) + { bar: { order: 'desc' } } + ], subject.to_hash + ) end - should "be empty" do + should 'be empty' do subject = OpenSearch::DSL::Search::Sort.new assert_equal subject.empty?, true end - should "not be empty" do + should 'not be empty' do subject = OpenSearch::DSL::Search::Sort.new foo: { order: 'desc' } assert_equal subject.empty?, false end - context "#to_hash" do - should "not duplicate values when defined by arguments" do + context '#to_hash' do + should 'not duplicate values when defined by arguments' do subject = OpenSearch::DSL::Search::Sort.new foo: { order: 'desc' } assert_equal(subject.to_hash, subject.to_hash) end - should "not duplicate values when defined by a block" do + should 'not duplicate values when defined by a block' do subject = OpenSearch::DSL::Search::Sort.new do by :foo end diff --git a/opensearch-dsl/test/unit/search_suggest_test.rb b/opensearch-dsl/test/unit/search_suggest_test.rb index b2d6314f0..9da0b2250 100644 --- a/opensearch-dsl/test/unit/search_suggest_test.rb +++ b/opensearch-dsl/test/unit/search_suggest_test.rb @@ -31,12 +31,12 @@ module Test class SearchSuggestTest < ::OpenSearch::Test::UnitTestCase subject { OpenSearch::DSL::Search::Suggest.new :foo } - context "Search suggest" do - should "be an empty hash by default" do + context 'Search suggest' do + should 'be an empty hash by default' do assert_equal({ foo: {} }, subject.to_hash) end - should "contain options" do + should 'contain options' do subject = OpenSearch::DSL::Search::Suggest.new :foo, boo: 'bam' assert_equal({ foo: { boo: 'bam' } }, subject.to_hash) end diff --git a/opensearch-dsl/test/unit/search_test.rb b/opensearch-dsl/test/unit/search_test.rb index 7ebde4588..86969d6e9 100644 --- a/opensearch-dsl/test/unit/search_test.rb +++ b/opensearch-dsl/test/unit/search_test.rb @@ -31,8 +31,8 @@ module Test class SearchTest < ::OpenSearch::Test::UnitTestCase subject { OpenSearch::DSL::Search::Search.new } - context "The Search module" do - should "have the search method on instance" do + context 'The Search module' do + should 'have the search method on instance' do class DummySearchReceiver include OpenSearch::DSL::Search end @@ -40,7 +40,7 @@ class DummySearchReceiver assert_instance_of OpenSearch::DSL::Search::Search, DummySearchReceiver.new.search end - should "have the search method on module" do + should 'have the search method on module' do class DummySearchReceiver include OpenSearch::DSL::Search end @@ -48,7 +48,7 @@ class DummySearchReceiver assert_instance_of OpenSearch::DSL::Search::Search, OpenSearch::DSL::Search.search end - should "have access to the calling context" do + should 'have access to the calling context' do class DummySearchReceiver include OpenSearch::DSL::Search @@ -76,194 +76,192 @@ def search_definition end end - assert_equal({from: 42, - size: 'foo', - stored_fields: ['term'], - filter: { and: [ { term: { thang: 'foo' } }, - { term: { attributes: 42 } }]}}, - DummySearchReceiver.new.search_definition.to_hash) + assert_equal({ from: 42, + size: 'foo', + stored_fields: ['term'], + filter: { and: [{ term: { thang: 'foo' } }, + { term: { attributes: 42 } }] } }, + DummySearchReceiver.new.search_definition.to_hash) end end - context "The Search class" do - - context "with query" do - should "take the query as a literal value" do + context 'The Search class' do + context 'with query' do + should 'take the query as a literal value' do subject.query foo: 'bar' - assert_equal({query: { foo: 'bar' }}, subject.to_hash) + assert_equal({ query: { foo: 'bar' } }, subject.to_hash) end - should "take the query as a block" do - OpenSearch::DSL::Search::Query.expects(:new).returns({foo: 'bar'}) - subject.query do; end - assert_equal({query: { foo: 'bar' }}, subject.to_hash) + should 'take the query as a block' do + OpenSearch::DSL::Search::Query.expects(:new).returns({ foo: 'bar' }) + subject.query { ; } + assert_equal({ query: { foo: 'bar' } }, subject.to_hash) end - should "allow chaining" do + should 'allow chaining' do assert_instance_of OpenSearch::DSL::Search::Search, subject.query(:foo) assert_instance_of OpenSearch::DSL::Search::Search, subject.query(:foo).query(:bar) end - should "be converted to hash" do + should 'be converted to hash' do assert_equal({}, subject.to_hash) subject.query foo: 'bar' - assert_equal({query: { foo: 'bar' }}, subject.to_hash) + assert_equal({ query: { foo: 'bar' } }, subject.to_hash) end - should "have a getter/setter method" do + should 'have a getter/setter method' do assert_nil subject.query subject.query = Object.new assert_not_nil subject.query end end - context "with filter" do - should "take the filter as a literal value" do + context 'with filter' do + should 'take the filter as a literal value' do subject.filter foo: 'bar' - assert_equal({filter: { foo: 'bar' }}, subject.to_hash) + assert_equal({ filter: { foo: 'bar' } }, subject.to_hash) end - should "take the filter as a block" do - OpenSearch::DSL::Search::Filter.expects(:new).returns({foo: 'bar'}) - subject.filter do; end - assert_equal({filter: { foo: 'bar' }}, subject.to_hash) + should 'take the filter as a block' do + OpenSearch::DSL::Search::Filter.expects(:new).returns({ foo: 'bar' }) + subject.filter { ; } + assert_equal({ filter: { foo: 'bar' } }, subject.to_hash) end - should "allow chaining" do + should 'allow chaining' do assert_instance_of OpenSearch::DSL::Search::Search, subject.filter(:foo) assert_instance_of OpenSearch::DSL::Search::Search, subject.filter(:foo).filter(:bar) end - should "be converted to hash" do + should 'be converted to hash' do assert_equal({}, subject.to_hash) subject.filter foo: 'bar' - assert_equal({filter: { foo: 'bar' }}, subject.to_hash) + assert_equal({ filter: { foo: 'bar' } }, subject.to_hash) end - should "have a getter/setter method" do + should 'have a getter/setter method' do assert_nil subject.filter subject.filter = Object.new assert_not_nil subject.filter end end - context "with post_filter" do - should "take the filter as a literal value" do + context 'with post_filter' do + should 'take the filter as a literal value' do subject.post_filter foo: 'bar' - assert_equal({post_filter: { foo: 'bar' }}, subject.to_hash) + assert_equal({ post_filter: { foo: 'bar' } }, subject.to_hash) end - should "take the filter as a block" do - OpenSearch::DSL::Search::Filter.expects(:new).returns({foo: 'bar'}) - subject.post_filter do; end - assert_equal({post_filter: { foo: 'bar' }}, subject.to_hash) + should 'take the filter as a block' do + OpenSearch::DSL::Search::Filter.expects(:new).returns({ foo: 'bar' }) + subject.post_filter { ; } + assert_equal({ post_filter: { foo: 'bar' } }, subject.to_hash) end - should "allow chaining" do + should 'allow chaining' do assert_instance_of OpenSearch::DSL::Search::Search, subject.post_filter(:foo) assert_instance_of OpenSearch::DSL::Search::Search, subject.post_filter(:foo).post_filter(:bar) end - should "be converted to hash" do + should 'be converted to hash' do assert_equal({}, subject.to_hash) subject.post_filter foo: 'bar' - assert_equal({post_filter: { foo: 'bar' }}, subject.to_hash) + assert_equal({ post_filter: { foo: 'bar' } }, subject.to_hash) end - should "have a getter/setter method" do + should 'have a getter/setter method' do assert_nil subject.post_filter subject.post_filter = Object.new assert_not_nil subject.post_filter end end - context "with aggregations" do - should "take the aggregation as a literal value" do + context 'with aggregations' do + should 'take the aggregation as a literal value' do subject.aggregation :foo, terms: 'bar' - assert_equal({aggregations: { foo: { terms: "bar" } } }, subject.to_hash) + assert_equal({ aggregations: { foo: { terms: 'bar' } } }, subject.to_hash) end - should "take the aggregation as a block" do - OpenSearch::DSL::Search::Aggregation.expects(:new).returns({tam: 'tam'}) + should 'take the aggregation as a block' do + OpenSearch::DSL::Search::Aggregation.expects(:new).returns({ tam: 'tam' }) subject.aggregation :foo do; end - assert_equal({aggregations: { foo: { tam: 'tam' } } }, subject.to_hash) + assert_equal({ aggregations: { foo: { tam: 'tam' } } }, subject.to_hash) end - should "allow chaining" do + should 'allow chaining' do assert_instance_of OpenSearch::DSL::Search::Search, subject.aggregation(:foo) assert_instance_of OpenSearch::DSL::Search::Search, subject.aggregation(:foo).aggregation(:bar) end - should "be converted to hash" do + should 'be converted to hash' do assert_equal({}, subject.to_hash) subject.post_filter foo: 'bar' - assert_equal({post_filter: { foo: 'bar' }}, subject.to_hash) + assert_equal({ post_filter: { foo: 'bar' } }, subject.to_hash) end - should "have a getter/setter method" do + should 'have a getter/setter method' do assert_nil subject.aggregations subject.aggregations = { foo: Object.new } assert_not_nil subject.aggregations end end - context "with sorting" do - should "be converted to hash" do + context 'with sorting' do + should 'be converted to hash' do subject.sort :foo - assert_equal( { sort: [ :foo ] }, subject.to_hash ) + assert_equal({ sort: [:foo] }, subject.to_hash) end - should "have a getter method" do + should 'have a getter method' do assert_nil subject.sort subject.sort :foo assert_instance_of OpenSearch::DSL::Search::Sort, subject.sort end - should "have a setter method" do + should 'have a setter method' do sort_object = OpenSearch::DSL::Search::Sort.new foo: { order: 'desc' }, bar: { order: 'asc' } subject.sort = sort_object assert_not_nil subject.sort - assert_equal( { sort: [ { foo: { order: "desc" }, bar: { order: "asc" } } ] }, subject.to_hash ) + assert_equal({ sort: [{ foo: { order: 'desc' }, bar: { order: 'asc' } }] }, subject.to_hash) end end - context "with suggest" do - should "be converted to hash" do + context 'with suggest' do + should 'be converted to hash' do subject.suggest :foo, { bar: 'bam' } - assert_equal( { suggest: { foo: { bar: 'bam' } } }, subject.to_hash ) + assert_equal({ suggest: { foo: { bar: 'bam' } } }, subject.to_hash) end - should "have a getter/setter method" do + should 'have a getter/setter method' do assert_nil subject.suggest subject.suggest = Object.new assert_not_nil subject.suggest end end - context "with highlighting" do - should "be converted to a hash" do + context 'with highlighting' do + should 'be converted to a hash' do subject.highlight foo: 'bar' assert_not_nil subject.highlight - assert_equal( { highlight: { foo: 'bar' } }, subject.to_hash ) + assert_equal({ highlight: { foo: 'bar' } }, subject.to_hash) end end - context "with options" do - should "encode options" do + context 'with options' do + should 'encode options' do subject.explain true - subject.fields [:foo, :bar] - assert_equal( { explain: true, fields: [:foo, :bar] }, subject.to_hash ) + subject.fields %i[foo bar] + assert_equal({ explain: true, fields: %i[foo bar] }, subject.to_hash) end - should "raise an exception for unknown method" do + should 'raise an exception for unknown method' do assert_raise(NoMethodError) { subject.foobar true } end end - end end end diff --git a/opensearch-dsl/test/unit/utils_test.rb b/opensearch-dsl/test/unit/utils_test.rb index 1db2b1f67..b8cfdd7b4 100644 --- a/opensearch-dsl/test/unit/utils_test.rb +++ b/opensearch-dsl/test/unit/utils_test.rb @@ -29,16 +29,16 @@ module OpenSearch module Test class UtilsTest < ::OpenSearch::Test::UnitTestCase - context "Utils" do - should "convert a string to camelcase" do + context 'Utils' do + should 'convert a string to camelcase' do assert_equal 'Foo', OpenSearch::DSL::Utils.__camelize('foo') end - should "convert an underscored string to camelcase" do + should 'convert an underscored string to camelcase' do assert_equal 'FooBar', OpenSearch::DSL::Utils.__camelize('foo_bar') end - should "convert a symbol" do + should 'convert a symbol' do assert_equal 'FooBar', OpenSearch::DSL::Utils.__camelize(:foo_bar) end end diff --git a/opensearch-ruby/Gemfile b/opensearch-ruby/Gemfile index 3c997167a..78fe27edf 100644 --- a/opensearch-ruby/Gemfile +++ b/opensearch-ruby/Gemfile @@ -29,10 +29,10 @@ source 'https://rubygems.org' # Specify your gem's dependencies in opensearch.gemspec gemspec -if File.exist? File.expand_path("../../opensearch-api/opensearch-api.gemspec", __FILE__) - gem 'opensearch-api', :path => File.expand_path("../../opensearch-api", __FILE__), :require => false +if File.exist? File.expand_path('../opensearch-api/opensearch-api.gemspec', __dir__) + gem 'opensearch-api', path: File.expand_path('../opensearch-api', __dir__), require: false end -if File.exist? File.expand_path("../../opensearch-transport/opensearch-transport.gemspec", __FILE__) - gem 'opensearch-transport', :path => File.expand_path("../../opensearch-transport", __FILE__), :require => false +if File.exist? File.expand_path('../opensearch-transport/opensearch-transport.gemspec', __dir__) + gem 'opensearch-transport', path: File.expand_path('../opensearch-transport', __dir__), require: false end diff --git a/opensearch-ruby/Rakefile b/opensearch-ruby/Rakefile index 7e97e19a0..992e5a5c1 100644 --- a/opensearch-ruby/Rakefile +++ b/opensearch-ruby/Rakefile @@ -65,5 +65,5 @@ end require 'yard' YARD::Rake::YardocTask.new(:doc) do |t| - t.options = %w| --embed-mixins --markup=markdown | + t.options = %w[--embed-mixins --markup=markdown] end diff --git a/opensearch-ruby/bin/opensearch_ruby_console b/opensearch-ruby/bin/opensearch_ruby_console index a51d22d02..52785889f 100755 --- a/opensearch-ruby/bin/opensearch_ruby_console +++ b/opensearch-ruby/bin/opensearch_ruby_console @@ -10,11 +10,9 @@ require 'opensearch-transport' require 'opensearch-api' gems_not_loaded = ['opensearch-dsl'].reject do |gem| - begin - (require gem) || true - rescue LoadError - false - end + (require gem) || true +rescue LoadError + false end unless gems_not_loaded.empty? diff --git a/opensearch-ruby/lib/opensearch.rb b/opensearch-ruby/lib/opensearch.rb index 6cc1bbd6d..e50acde13 100644 --- a/opensearch-ruby/lib/opensearch.rb +++ b/opensearch-ruby/lib/opensearch.rb @@ -81,7 +81,7 @@ def verify_version_and_distribution(version, distribution) if distribution == 'opensearch' @verified = true elsif Gem::Version.new(version) >= Gem::Version.new('6.0.0') && - Gem::Version.new(version) < Gem::Version.new('8.0.0') + Gem::Version.new(version) < Gem::Version.new('8.0.0') @verified = true else raise OpenSearch::UnsupportedProductError diff --git a/opensearch-ruby/opensearch-ruby.gemspec b/opensearch-ruby/opensearch-ruby.gemspec index 3675f0230..b469a81ad 100644 --- a/opensearch-ruby/opensearch-ruby.gemspec +++ b/opensearch-ruby/opensearch-ruby.gemspec @@ -24,16 +24,16 @@ # specific language governing permissions and limitations # under the License. -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'opensearch/version' -signing_key_path = File.expand_path("../gem-private_key.pem") +signing_key_path = File.expand_path('../gem-private_key.pem') Gem::Specification.new do |s| s.name = 'opensearch-ruby' s.version = OpenSearch::VERSION - s.authors = ['Jayesh Hathila', 'Vamshi Vijay Nakkirtha', 'Vijayan Balasubramanian' , 'Yuvraj Jaiswal'] + s.authors = ['Jayesh Hathila', 'Vamshi Vijay Nakkirtha', 'Vijayan Balasubramanian', 'Yuvraj Jaiswal'] s.email = ['jayehh@amazon.com', 'vamshin@amazon.com', 'balasvij@amazon.com', 'jaiyuvra@amazon.com'] s.summary = 'Ruby integrations for OpenSearch' s.homepage = 'https://opensearch.org/docs/latest' @@ -41,14 +41,15 @@ Gem::Specification.new do |s| s.metadata = { 'homepage_uri' => 'https://opensearch.org/docs/latest/', 'source_code_uri' => 'https://github.com/opensearch-project/opensearch-ruby/tree/main', - 'bug_tracker_uri' => 'https://github.com/opensearch-project/opensearch-ruby/issues' + 'bug_tracker_uri' => 'https://github.com/opensearch-project/opensearch-ruby/issues', + 'rubygems_mfa_required' => 'true' } s.files = `git ls-files`.split($/) s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) } - s.executables << 'opensearch_ruby_console' - s.test_files = s.files.grep(%r{^(test|spec|features)/}) + s.executables << 'opensearch_ruby_console' + s.test_files = s.files.grep(%r{^(test|spec|features)/}) - if $PROGRAM_NAME.end_with?("gem") && ARGV == ["build", __FILE__] && File.exist?(signing_key_path) + if $PROGRAM_NAME.end_with?('gem') && ARGV == ['build', __FILE__] && File.exist?(signing_key_path) s.signing_key = signing_key_path s.cert_chain = ['../certs/opensearch-rubygems.pem'] end @@ -56,13 +57,13 @@ Gem::Specification.new do |s| s.require_paths = ['lib'] s.bindir = 'bin' - s.extra_rdoc_files = [ 'README.md', 'LICENSE' ] - s.rdoc_options = [ '--charset=UTF-8' ] + s.extra_rdoc_files = ['README.md', 'LICENSE'] + s.rdoc_options = ['--charset=UTF-8'] s.required_ruby_version = '>= 2.4' - s.add_dependency 'opensearch-transport', '~> 2.0' s.add_dependency 'opensearch-api', '~> 2.1' + s.add_dependency 'opensearch-transport', '~> 2.0' s.add_development_dependency 'bundler' s.add_development_dependency 'byebug' unless defined?(JRUBY_VERSION) || defined?(Rubinius) diff --git a/opensearch-ruby/spec/integration/security_disabled/client_integration_spec.rb b/opensearch-ruby/spec/integration/security_disabled/client_integration_spec.rb index 969638361..5cc466cae 100644 --- a/opensearch-ruby/spec/integration/security_disabled/client_integration_spec.rb +++ b/opensearch-ruby/spec/integration/security_disabled/client_integration_spec.rb @@ -26,7 +26,7 @@ require 'spec_helper' require 'logger' -context 'OpenSearch client ' do +context 'OpenSearch client' do let(:logger) { Logger.new($stderr) } let(:client) do @@ -37,7 +37,7 @@ end context 'Integrates with opensearch API' do - it 'should perform the API methods' do + it 'performs the API methods' do expect do # Index a document client.index(index: 'test-index', id: '1', body: { title: 'Test' }) diff --git a/opensearch-ruby/spec/integration/security_enabled/client_integration_spec.rb b/opensearch-ruby/spec/integration/security_enabled/client_integration_spec.rb index 6ded44b9c..1cd0a0264 100644 --- a/opensearch-ruby/spec/integration/security_enabled/client_integration_spec.rb +++ b/opensearch-ruby/spec/integration/security_enabled/client_integration_spec.rb @@ -21,7 +21,7 @@ end context 'Integrates with opensearch API' do - it 'should perform the API methods' do + it 'performs the API methods' do expect do # Index a document client.index(index: 'test-index', id: '1', body: { title: 'Test' }) diff --git a/opensearch-ruby/spec/spec_helper.rb b/opensearch-ruby/spec/spec_helper.rb index 35538d633..b53d7038c 100644 --- a/opensearch-ruby/spec/spec_helper.rb +++ b/opensearch-ruby/spec/spec_helper.rb @@ -27,7 +27,7 @@ require 'opensearch' require 'rspec' -OPENSEARCH_URL = ENV['TEST_OPENSEARCH_SERVER'] || "http://localhost:#{(ENV['PORT'] || 9200)}" +OPENSEARCH_URL = ENV.fetch('TEST_OPENSEARCH_SERVER', nil) || "http://localhost:#{ENV.fetch('PORT', nil) || 9200}" raise URI::InvalidURIError unless OPENSEARCH_URL =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/ RSpec.configure do |config| diff --git a/opensearch-ruby/spec/unit/opensearch_product_validation_spec.rb b/opensearch-ruby/spec/unit/opensearch_product_validation_spec.rb index ffb82aa28..aaf0daace 100644 --- a/opensearch-ruby/spec/unit/opensearch_product_validation_spec.rb +++ b/opensearch-ruby/spec/unit/opensearch_product_validation_spec.rb @@ -124,6 +124,7 @@ def valid_requests_and_expectations context 'When the distribution is not present' do let(:body) { { 'version' => { 'number' => '2.0.0' } }.to_json } + it 'Fails validation' do verify_request_stub @@ -135,7 +136,6 @@ def valid_requests_and_expectations end end - context 'When the Elasticsearch version is >= 6.0' do context 'With a valid Elasticsearch response' do let(:body) { { 'version' => { 'number' => '6.0.0' } }.to_json } @@ -152,7 +152,6 @@ def valid_requests_and_expectations valid_requests_and_expectations end end - end context 'When the Elasticsearch version is >= 8.0.0' do @@ -175,6 +174,7 @@ def valid_requests_and_expectations context 'When there is no version data' do let(:body) { {}.to_json } + it 'Raises an exception and client doesnae work' do verify_request_stub error_requests_and_expectations @@ -183,10 +183,11 @@ def valid_requests_and_expectations context 'When doing a yaml content-type request' do let(:client) do - OpenSearch::Client.new(transport_options: {headers: { accept: 'application/yaml', content_type: 'application/yaml' }}) + OpenSearch::Client.new(transport_options: { headers: { accept: 'application/yaml', + content_type: 'application/yaml' } }) end - let(:headers) { { 'content-type' => 'application/yaml'} } + let(:headers) { { 'content-type' => 'application/yaml' } } let(:body) { "---\nversion:\n number: \"2.0.0\"\n distribution: \"opensearch\"\n" } it 'validates' do diff --git a/opensearch-transport/Gemfile b/opensearch-transport/Gemfile index 386dd69b0..0fcb13dd1 100644 --- a/opensearch-transport/Gemfile +++ b/opensearch-transport/Gemfile @@ -37,7 +37,7 @@ if File.exist? File.expand_path('../opensearch-ruby/opensearch-ruby.gemspec', __ gem 'opensearch-ruby', path: File.expand_path('../opensearch-ruby', __dir__), require: false end -gem 'faraday', ENV['FARADAY_VERSION'], require: false if ENV.key?('FARADAY_VERSION') +gem 'faraday', ENV.fetch('FARADAY_VERSION', nil), require: false if ENV.key?('FARADAY_VERSION') group :development, :test do gem 'rspec' diff --git a/opensearch-transport/Rakefile b/opensearch-transport/Rakefile index c76c4ab06..f29ceb61d 100644 --- a/opensearch-transport/Rakefile +++ b/opensearch-transport/Rakefile @@ -24,11 +24,11 @@ # specific language governing permissions and limitations # under the License. -require "bundler/gem_tasks" +require 'bundler/gem_tasks' -desc "Run unit tests" -task :default => 'test:unit' -task :test => 'test:unit' +desc 'Run unit tests' +task default: 'test:unit' +task test: 'test:unit' # ----- Test tasks ------------------------------------------------------------ @@ -68,14 +68,13 @@ namespace :test do test.libs << 'lib' << 'test' test.test_files = FileList['test/profile/**/*_test.rb'] end - end # ----- Documentation tasks --------------------------------------------------- require 'yard' YARD::Rake::YardocTask.new(:doc) do |t| - t.options = %w| --embed-mixins --markup=markdown | + t.options = %w[--embed-mixins --markup=markdown] end # ----- Code analysis tasks --------------------------------------------------- diff --git a/opensearch-transport/lib/opensearch/transport/client.rb b/opensearch-transport/lib/opensearch/transport/client.rb index 588a79eb4..c1da24bc9 100644 --- a/opensearch-transport/lib/opensearch/transport/client.rb +++ b/opensearch-transport/lib/opensearch/transport/client.rb @@ -39,7 +39,7 @@ class Client require 'logger' logger = Logger.new(STDERR) logger.progname = 'opensearch' - logger.formatter = proc { |severity, datetime, progname, msg| "#{datetime}: #{msg}\n" } + logger.formatter = proc { |_severity, datetime, _progname, msg| "#{datetime}: #{msg}\n" } logger end @@ -47,7 +47,7 @@ class Client require 'logger' logger = Logger.new(STDERR) logger.progname = 'opensearch.tracer' - logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" } + logger.formatter = proc { |_severity, _datetime, _progname, msg| "#{msg}\n" } logger end @@ -134,11 +134,11 @@ class Client # # @yield [faraday] Access and configure the `Faraday::Connection` instance directly with a block # - def initialize(arguments={}, &block) - @options = arguments.each_with_object({}){ |(k,v), args| args[k.to_sym] = v } + def initialize(arguments = {}, &block) + @options = arguments.each_with_object({}) { |(k, v), args| args[k.to_sym] = v } @arguments = @options - @arguments[:logger] ||= @arguments[:log] ? DEFAULT_LOGGER.call() : nil - @arguments[:tracer] ||= @arguments[:trace] ? DEFAULT_TRACER.call() : nil + @arguments[:logger] ||= @arguments[:log] ? DEFAULT_LOGGER.call : nil + @arguments[:tracer] ||= @arguments[:trace] ? DEFAULT_TRACER.call : nil @arguments[:reload_connections] ||= false @arguments[:retry_on_failure] ||= false @arguments[:reload_on_failure] ||= false @@ -155,7 +155,7 @@ def initialize(arguments={}, &block) @arguments[:host] || @arguments[:url] || @arguments[:urls] || - ENV['OPENSEARCH_URL'] || + ENV.fetch('OPENSEARCH_URL', nil) || DEFAULT_HOST) @send_get_body_as = @arguments[:send_get_body_as] || 'GET' @@ -203,7 +203,7 @@ def set_api_key end def set_compatibility_header - return unless ['1', 'true'].include?(ENV['ELASTIC_CLIENT_APIVERSIONING']) + return unless %w[1 true].include?(ENV.fetch('ELASTIC_CLIENT_APIVERSIONING', nil)) add_header( { @@ -259,15 +259,15 @@ def extract_cloud_creds(arguments) # def __extract_hosts(hosts_config) hosts = case hosts_config - when String - hosts_config.split(',').map { |h| h.strip! || h } - when Array - hosts_config - when Hash, URI - [ hosts_config ] - else - Array(hosts_config) - end + when String + hosts_config.split(',').map { |h| h.strip! || h } + when Array + hosts_config + when Hash, URI + [hosts_config] + else + Array(hosts_config) + end host_list = hosts.map { |host| __parse_host(host) } @options[:randomize_hosts] ? host_list.shuffle! : host_list @@ -276,7 +276,7 @@ def __extract_hosts(hosts_config) def __parse_host(host) host_parts = case host when String - if host =~ /^[a-z]+\:\/\// + if host =~ %r{^[a-z]+://} # Construct a new `URI::Generic` directly from the array returned by URI::split. # This avoids `URI::HTTP` and `URI::HTTPS`, which supply default ports. uri = URI::Generic.new(*URI.split(host)) @@ -331,22 +331,21 @@ def __parse_host(host) # def __auto_detect_adapter # Get the Faraday adapter list without initializing it. - if Faraday::Adapter.respond_to?(:registered_middleware) # Faraday 2.x - adapter = ->(name) { Faraday::Adapter.registered_middleware[name] } - elsif Faraday::Adapter.respond_to?(:fetch_middleware) # Faraday 1.x - adapter = ->(name) { Faraday::Adapter.fetch_middleware(name) } - else - adapter = {} # fallback behavior that should never happen - end + adapter = if Faraday::Adapter.respond_to?(:registered_middleware) # Faraday 2.x + ->(name) { Faraday::Adapter.registered_middleware[name] } + elsif Faraday::Adapter.respond_to?(:fetch_middleware) # Faraday 1.x + ->(name) { Faraday::Adapter.fetch_middleware(name) } + else + {} # fallback behavior that should never happen + end # Pick an adapter that has both the client and adapter defined. - case - when defined?(::Patron) && adapter[:patron] + if defined?(::Patron) && adapter[:patron] :patron - when defined?(::Typhoeus) && adapter[:typhoeus] + elsif defined?(::Typhoeus) && adapter[:typhoeus] :typhoeus - when defined?(::HTTPClient) && adapter[:httpclient] + elsif defined?(::HTTPClient) && adapter[:httpclient] :httpclient - when defined?(::Net::HTTP::Persistent) && adapter[:net_http_persistent] + elsif defined?(::Net::HTTP::Persistent) && adapter[:net_http_persistent] :net_http_persistent else ::Faraday.default_adapter diff --git a/opensearch-transport/lib/opensearch/transport/redacted.rb b/opensearch-transport/lib/opensearch/transport/redacted.rb index 475a876be..48a0607e9 100644 --- a/opensearch-transport/lib/opensearch/transport/redacted.rb +++ b/opensearch-transport/lib/opensearch/transport/redacted.rb @@ -26,23 +26,21 @@ module OpenSearch module Transport - # Class for wrapping a hash that could have sensitive data. # When printed, the sensitive values will be redacted. # # @since 6.1.1 class Redacted < ::Hash - def initialize(elements = nil) super() - (elements || {}).each_pair{ |key, value| self[key] = value } + (elements || {}).each_pair { |key, value| self[key] = value } end # The keys whose values will be redacted. # # @since 6.1.1 - SENSITIVE_KEYS = [ :password, - :pwd ].freeze + SENSITIVE_KEYS = %i[password + pwd].freeze # The replacement string used in place of the value for sensitive keys. # @@ -77,6 +75,7 @@ def redacted_string(method) def redact(k, v, method) return STRING_REPLACEMENT if SENSITIVE_KEYS.include?(k.to_sym) + v.send(method) end end diff --git a/opensearch-transport/lib/opensearch/transport/transport/base.rb b/opensearch-transport/lib/opensearch/transport/transport/base.rb index 35b63c569..963b1cb9a 100644 --- a/opensearch-transport/lib/opensearch/transport/transport/base.rb +++ b/opensearch-transport/lib/opensearch/transport/transport/base.rb @@ -27,7 +27,6 @@ module OpenSearch module Transport module Transport - # @abstract Module with common functionality for transport implementations. # module Base @@ -39,7 +38,7 @@ module Base DEFAULT_RESURRECT_AFTER = 60 # Seconds DEFAULT_MAX_RETRIES = 3 # Requests DEFAULT_SERIALIZER_CLASS = Serializer::MultiJson - SANITIZED_PASSWORD = '*' * (rand(14)+1) + SANITIZED_PASSWORD = '*' * rand(1..14) attr_reader :hosts, :options, :connections, :counter, :last_request_at, :protocol attr_accessor :serializer, :sniffer, :logger, :tracer, @@ -68,7 +67,7 @@ def initialize(arguments = {}, &block) @compression = !!@options[:compression] @connections = __build_connections - @serializer = options[:serializer] || ( options[:serializer_class] ? options[:serializer_class].new(self) : DEFAULT_SERIALIZER_CLASS.new(self) ) + @serializer = options[:serializer] || (options[:serializer_class] ? options[:serializer_class].new(self) : DEFAULT_SERIALIZER_CLASS.new(self)) @protocol = options[:protocol] || DEFAULT_PROTOCOL @logger = options[:logger] @@ -92,11 +91,11 @@ def initialize(arguments = {}, &block) # @return [Connections::Connection] # @see Connections::Collection#get_connection # - def get_connection(options={}) + def get_connection(options = {}) resurrect_dead_connections! if Time.now > @last_request_at + @resurrect_after @counter_mtx.synchronize { @counter += 1 } - reload_connections! if reload_connections && counter % reload_after == 0 + reload_connections! if reload_connections && counter % reload_after == 0 connections.get_connection(options) end @@ -106,10 +105,10 @@ def get_connection(options={}) # def reload_connections! hosts = sniffer.hosts - __rebuild_connections :hosts => hosts, :options => options + __rebuild_connections hosts: hosts, options: options self rescue SnifferTimeoutError - log_error "[SnifferTimeoutError] Timeout when reloading connections." + log_error '[SnifferTimeoutError] Timeout when reloading connections.' self end @@ -129,7 +128,7 @@ def resurrect_dead_connections! # @return [Connections::Collection] # @api private # - def __rebuild_connections(arguments={}) + def __rebuild_connections(arguments = {}) @state_mutex.synchronize do @hosts = arguments[:hosts] || [] @options = arguments[:options] || {} @@ -137,7 +136,7 @@ def __rebuild_connections(arguments={}) __close_connections new_connections = __build_connections - stale_connections = @connections.all.select { |c| ! new_connections.include?(c) } + stale_connections = @connections.all.select { |c| !new_connections.include?(c) } new_connections = new_connections.reject { |c| @connections.all.include?(c) } @connections.remove(stale_connections) @@ -155,18 +154,19 @@ def __rebuild_connections(arguments={}) # def __build_connections Connections::Collection.new \ - :connections => hosts.map { |host| - host[:protocol] = host[:scheme] || options[:scheme] || options[:http][:scheme] || DEFAULT_PROTOCOL - host[:port] ||= options[:port] || options[:http][:port] || DEFAULT_PORT - if (options[:user] || options[:http][:user]) && !host[:user] - host[:user] ||= options[:user] || options[:http][:user] - host[:password] ||= options[:password] || options[:http][:password] - end - - __build_connection(host, (options[:transport_options] || {}), @block) - }, - :selector_class => options[:selector_class], - :selector => options[:selector] + connections: hosts.map { |host| + host[:protocol] = + host[:scheme] || options[:scheme] || options[:http][:scheme] || DEFAULT_PROTOCOL + host[:port] ||= options[:port] || options[:http][:port] || DEFAULT_PORT + if (options[:user] || options[:http][:user]) && !host[:user] + host[:user] ||= options[:user] || options[:http][:user] + host[:password] ||= options[:password] || options[:http][:password] + end + + __build_connection(host, (options[:transport_options] || {}), @block) + }, + selector_class: options[:selector_class], + selector: options[:selector] end # @abstract Build and return a connection. @@ -176,8 +176,8 @@ def __build_connections # @return [Connections::Connection] # @api private # - def __build_connection(host, options={}, block=nil) - raise NoMethodError, "Implement this method in your class" + def __build_connection(_host, _options = {}, _block = nil) + raise NoMethodError, 'Implement this method in your class' end # Closes the connections collection @@ -192,11 +192,11 @@ def __close_connections # # @api private # - def __log_response(method, path, params, body, url, response, json, took, duration) + def __log_response(method, _path, _params, body, url, response, _json, took, duration) if logger - sanitized_url = url.to_s.gsub(/\/\/(.+):(.+)@/, '//' + '\1:' + SANITIZED_PASSWORD + '@') + sanitized_url = url.to_s.gsub(%r{//(.+):(.+)@}, '//' + '\1:' + SANITIZED_PASSWORD + '@') log_info "#{method.to_s.upcase} #{sanitized_url} " + - "[status:#{response.status}, request:#{sprintf('%.3fs', duration)}, query:#{took}]" + "[status:#{response.status}, request:#{format('%.3fs', duration)}, query:#{took}]" log_debug "> #{__convert_to_json(body)}" if body log_debug "< #{response.body}" end @@ -206,16 +206,17 @@ def __log_response(method, path, params, body, url, response, json, took, durati # # @api private # - def __trace(method, path, params, headers, body, url, response, json, took, duration) + def __trace(method, path, params, headers, body, _url, response, json, _took, duration) trace_url = "http://localhost:9200/#{path}?pretty" + - ( params.empty? ? '' : "&#{::Faraday::Utils::ParamsHash[params].to_query}" ) - trace_body = body ? " -d '#{__convert_to_json(body, :pretty => true)}'" : '' + (params.empty? ? '' : "&#{::Faraday::Utils::ParamsHash[params].to_query}") + trace_body = body ? " -d '#{__convert_to_json(body, pretty: true)}'" : '' trace_command = "curl -X #{method.to_s.upcase}" - trace_command += " -H '#{headers.collect { |k,v| "#{k}: #{v}" }.join(", ")}'" if headers && !headers.empty? + trace_command += " -H '#{headers.collect { |k, v| "#{k}: #{v}" }.join(', ')}'" if headers && !headers.empty? trace_command += " '#{trace_url}'#{trace_body}\n" tracer.info trace_command tracer.debug "# #{Time.now.iso8601} [#{response.status}] (#{format('%.3f', duration)}s)\n#" - tracer.debug json ? serializer.dump(json, :pretty => true).gsub(/^/, '# ').sub(/\}$/, "\n# }")+"\n" : "# #{response.body}\n" + tracer.debug json ? serializer.dump(json, pretty: true).gsub(/^/, '# ').sub(/\}$/, + "\n# }") + "\n" : "# #{response.body}\n" end # Raise error specific for the HTTP response status or a generic server error @@ -224,14 +225,14 @@ def __trace(method, path, params, headers, body, url, response, json, took, dura # def __raise_transport_error(response) error = ERRORS[response.status] || ServerError - raise error.new "[#{response.status}] #{response.body}" + raise error, "[#{response.status}] #{response.body}" end # Converts any non-String object to JSON # # @api private # - def __convert_to_json(o=nil, options={}) + def __convert_to_json(o = nil, options = {}) o = o.is_a?(String) ? o : serializer.dump(o, options) end @@ -267,7 +268,7 @@ def __full_url(host) # @raise [ServerError] If request failed on server # @raise [Error] If no connection is available # - def perform_request(method, path, params = {}, body = nil, headers = nil, opts = {}, &block) + def perform_request(method, path, params = {}, body = nil, _headers = nil, opts = {}, &block) raise NoMethodError, 'Implement this method in your transport class' unless block_given? start = Time.now @@ -275,10 +276,10 @@ def perform_request(method, path, params = {}, body = nil, headers = nil, opts = reload_on_failure = opts.fetch(:reload_on_failure, @options[:reload_on_failure]) max_retries = if opts.key?(:retry_on_failure) - opts[:retry_on_failure] === true ? DEFAULT_MAX_RETRIES : opts[:retry_on_failure] - elsif options.key?(:retry_on_failure) - options[:retry_on_failure] === true ? DEFAULT_MAX_RETRIES : options[:retry_on_failure] - end + opts[:retry_on_failure] === true ? DEFAULT_MAX_RETRIES : opts[:retry_on_failure] + elsif options.key?(:retry_on_failure) + options[:retry_on_failure] === true ? DEFAULT_MAX_RETRIES : options[:retry_on_failure] + end params = params.clone @@ -286,7 +287,7 @@ def perform_request(method, path, params = {}, body = nil, headers = nil, opts = begin tries += 1 - connection = get_connection or raise Error.new('Cannot get new connection from pool.') + connection = get_connection or raise(Error, 'Cannot get new connection from pool.') if connection.connection.respond_to?(:params) && connection.connection.params.respond_to?(:to_hash) params = connection.connection.params.merge(params.to_hash) @@ -299,8 +300,9 @@ def perform_request(method, path, params = {}, body = nil, headers = nil, opts = connection.healthy! if connection.failures > 0 # Raise an exception so we can catch it for `retry_on_status` - __raise_transport_error(response) if response.status.to_i >= 300 && @retry_on_status.include?(response.status.to_i) - + if response.status.to_i >= 300 && @retry_on_status.include?(response.status.to_i) + __raise_transport_error(response) + end rescue OpenSearch::Transport::Transport::ServerError => e if response && @retry_on_status.include?(response.status) log_warn "[#{e.class}] Attempt #{tries} to get response from #{url}" @@ -313,7 +315,6 @@ def perform_request(method, path, params = {}, body = nil, headers = nil, opts = else raise e end - rescue *host_unreachable_exceptions => e log_error "[#{e.class}] #{e.message} #{connection.host.inspect}" @@ -335,35 +336,43 @@ def perform_request(method, path, params = {}, body = nil, headers = nil, opts = else raise e end - rescue Exception => e log_fatal "[#{e.class}] #{e.message} (#{connection.host.inspect if connection})" raise e - - end #/begin + end # /begin duration = Time.now - start if response.status.to_i >= 300 - __log_response method, path, params, body, url, response, nil, 'N/A', duration - __trace method, path, params, connection.connection.headers, body, url, response, nil, 'N/A', duration if tracer + __log_response method, path, params, body, url, response, nil, 'N/A', duration + if tracer + __trace method, path, params, connection.connection.headers, body, url, response, nil, 'N/A', + duration + end # Log the failure only when `ignore` doesn't match the response status - unless ignore.include?(response.status.to_i) - log_fatal "[#{response.status}] #{response.body}" - end + log_fatal "[#{response.status}] #{response.body}" unless ignore.include?(response.status.to_i) __raise_transport_error response unless ignore.include?(response.status.to_i) end - json = serializer.load(response.body) if response.body && !response.body.empty? && response.headers && response.headers["content-type"] =~ /json/ - took = (json['took'] ? sprintf('%.3fs', json['took']/1000.0) : 'n/a') rescue 'n/a' + if response.body && !response.body.empty? && response.headers && response.headers['content-type'] =~ /json/ + json = serializer.load(response.body) + end + took = begin + (json['took'] ? format('%.3fs', json['took'] / 1000.0) : 'n/a') + rescue StandardError + 'n/a' + end unless ignore.include?(response.status.to_i) - __log_response method, path, params, body, url, response, json, took, duration + __log_response method, path, params, body, url, response, json, took, duration end - __trace method, path, params, connection.connection.headers, body, url, response, nil, 'N/A', duration if tracer + if tracer + __trace method, path, params, connection.connection.headers, body, url, response, nil, 'N/A', + duration + end warnings(response.headers['warning']) if response.headers&.[]('warning') @@ -384,9 +393,9 @@ def host_unreachable_exceptions private USER_AGENT_STR = 'User-Agent'.freeze - USER_AGENT_REGEX = /user\-?\_?agent/ + USER_AGENT_REGEX = /user-?_?agent/ CONTENT_TYPE_STR = 'Content-Type'.freeze - CONTENT_TYPE_REGEX = /content\-?\_?type/ + CONTENT_TYPE_REGEX = /content-?_?type/ DEFAULT_CONTENT_TYPE = 'application/json'.freeze GZIP = 'gzip'.freeze ACCEPT_ENCODING = 'Accept-Encoding'.freeze @@ -400,7 +409,7 @@ def decompress_response(body) io = StringIO.new(body) gzip_reader = if RUBY_ENCODING - Zlib::GzipReader.new(io, :encoding => 'ASCII-8BIT') + Zlib::GzipReader.new(io, encoding: 'ASCII-8BIT') else Zlib::GzipReader.new(io) end @@ -408,7 +417,7 @@ def decompress_response(body) end def gzipped?(body) - body[0..1].unpack(HEX_STRING_DIRECTIVE)[0] == GZIP_FIRST_TWO_BYTES + body[0..1].unpack1(HEX_STRING_DIRECTIVE) == GZIP_FIRST_TWO_BYTES end def use_compression? @@ -424,14 +433,14 @@ def apply_headers(client, options) end def find_value(hash, regex) - key_value = hash.find { |k,v| k.to_s.downcase =~ regex } + key_value = hash.find { |k, _v| k.to_s.downcase =~ regex } if key_value hash.delete(key_value[0]) key_value[1] end end - def user_agent_header(client) + def user_agent_header(_client) @user_agent ||= begin meta = ["RUBY_VERSION: #{RUBY_VERSION}"] if RbConfig::CONFIG && RbConfig::CONFIG['host_os']