Class: Esse::AsyncIndexing::Actions::CoerceIndexRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/esse/async_indexing/actions/coerce_index_repository.rb

Class Method Summary collapse

Class Method Details

.call(index_class_name, repo_name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/esse/async_indexing/actions/coerce_index_repository.rb', line 4

def self.call(index_class_name, repo_name)
  index_class = begin
    Object.const_get(index_class_name)
  rescue NameError
    raise(ArgumentError, "Index class #{index_class_name} not found")
  end

  repo_class = index_class.repo_hash[repo_name.to_s]
  repo_class ||= if repo_name.include?("::")
    index_class.repo_hash.map { |_, v| [v.to_s, v] }.to_h[repo_name]
  end
  if repo_class.nil?
    raise ArgumentError, <<~MSG
      No repo named "#{repo_name}" found in #{index_class_name}. Use the `repository` method to define one:

        repository :#{repo_name} do
          # collection ...
          # document ...
        end
    MSG
  end

  [index_class, repo_class]
end