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.
Showing
Please register or sign in to comment