Method: SearchFlip::Index::ClassMethods#with_settings

Defined in:
lib/search_flip/index.rb

#with_settings(index_name: nil, connection: nil) ⇒ Class

Creates an anonymous class inheriting from the current index with a custom index name and/or connection. This is e.g. useful when working with aliases or proxies.

Examples:

Basic usage

UserIndex.with_settings(index_name: 'new_user_index')
# => #<Class:0x...>

Working with aliases

new_index = UserIndex.with_settings(index_name: 'new_user_index')
new_index.create_index
new_index.import User.all
new_index.connection.update_aliases("...")

Working with proxies

query = UserIndex.with_settings(connection: ProxyConnection).where("...")


94
95
96
97
98
99
# File 'lib/search_flip/index.rb', line 94

def with_settings(index_name: nil, connection: nil)
  Class.new(self).tap do |klass|
    klass.define_singleton_method(:index_name) { index_name } if index_name
    klass.define_singleton_method(:connection) { connection } if connection
  end
end