Class: AgnosticBackend::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/agnostic_backend/index.rb

Direct Known Subclasses

Cloudsearch::Index, Elasticsearch::Index

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(indexable_klass, primary: true, **options) ⇒ Index

Returns a new instance of Index.



6
7
8
9
10
11
# File 'lib/agnostic_backend/index.rb', line 6

def initialize(indexable_klass, primary: true, **options)
  @indexable_klass = indexable_klass
  @primary = primary
  @options = options
  parse_options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/agnostic_backend/index.rb', line 4

def options
  @options
end

Instance Method Details

#configure(new_schema = nil) ⇒ Object

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/agnostic_backend/index.rb', line 29

def configure(new_schema = nil)
  raise NotImplementedError
end

#indexerObject

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/agnostic_backend/index.rb', line 25

def indexer
  raise NotImplementedError
end

#nameObject



17
18
19
# File 'lib/agnostic_backend/index.rb', line 17

def name
  @indexable_klass.index_name
end

#parse_option(option_name, optional: false, default: nil) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/agnostic_backend/index.rb', line 37

def parse_option(option_name, optional: false, default: nil)
  if options.has_key?(option_name)
    options[option_name]
  elsif optional
    default
  else
    raise "#{option_name} must be specified"
  end
end

#parse_optionsObject

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/agnostic_backend/index.rb', line 33

def parse_options
  raise NotImplementedError
end

#primary?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/agnostic_backend/index.rb', line 13

def primary?
  @primary
end

#schemaObject



21
22
23
# File 'lib/agnostic_backend/index.rb', line 21

def schema
  @indexable_klass.schema
end