Commit 2e1c254d authored by Yorick Peterse's avatar Yorick Peterse

Fix path_to_repo in Elasticsearch::Git::Repository

In `Elasticsearch::Git::Repository` we would define `path_to_repo` as
follows:

    unless defined?(path_to_repo)
      def path_to_repo
        @path_to_repo.presence || raise(NotImplementedError, ...)
      end
    end

Prior to this commit, this module would be included into `Repository`
before it defined its own `path_to_repo` method, meaning we would not
use the above definition as intended. However, this _only_ worked
because the module was included before our custom definition. The
`defined?(path_to_repo)` call would always return false, because
`defined?` here checks for _class methods_, and not instance methods. As
a result, when moving `prepend` in `Repository` to the end of the file,
the above code would redefine `Repository#path_to_repo`.

To resolve this, we use `method_defined?` instead of `defined?`, which
allows us to check for the presence of an instance method. This ensures
that `Repository#path_to_repo` does not get overwritten when we include
this module.
parent bec7d22d
......@@ -331,7 +331,7 @@ module Elasticsearch
@repository_id
end
unless defined?(path_to_repo)
unless method_defined?(:path_to_repo)
def path_to_repo
@path_to_repo.presence || raise(NotImplementedError, 'Please, define "path_to_repo" method, or set "path_to_repo" via "repository_for_indexing" method')
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment