Method: Esse::Index::ClassMethods#repo

Defined in:
lib/esse/index/type.rb

#repo(name = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/esse/index/type.rb', line 12

def repo(name = nil)
  if name.nil? && repo_hash.size == 1
    name = repo_hash.keys.first
  elsif name.nil? && repo_hash.size > 1
    raise ArgumentError, "You can only call `repo' with a name when there is only one type defined."
  end
  name ||= DEFAULT_REPO_NAME

  repo_hash.fetch(name.to_s)
rescue KeyError
  raise ArgumentError, "    No repo named \"\#{name}\" found. Use the `repository' method to define one:\n\n      repository :\#{name} do\n        # collection ...\n        # document ...\n      end\n  MSG\nend\n"