Module: Noiseless::DSL::ClassMethods
- Included in:
- Model
- Defined in:
- lib/noiseless/dsl.rb
Instance Method Summary collapse
- #adapter(name = nil) ⇒ Object
- #bulk_importer(connection: nil) ⇒ Object
- #connection(name = nil) ⇒ Object
- #import ⇒ Object
- #import_scoped(scope) ⇒ Object
- #index_name(name = nil) ⇒ Object
- #mapping(&block) ⇒ Object
- #multi_search(models: nil, indexes: nil, connection: nil, &block) ⇒ Object
- #page(num = nil) ⇒ Object
- #per(num) ⇒ Object
- #reindex ⇒ Object
- #search_index(*names) ⇒ Object
- #searchable ⇒ Object
- #searchable_fields(*fields) ⇒ Object
Instance Method Details
#adapter(name = nil) ⇒ Object
21 22 23 24 |
# File 'lib/noiseless/dsl.rb', line 21 def adapter(name = nil) @adapter_name = name if name @adapter_name || Noiseless.config.default_adapter end |
#bulk_importer(connection: nil) ⇒ Object
48 49 50 |
# File 'lib/noiseless/dsl.rb', line 48 def bulk_importer(connection: nil) BulkImporter.new(self, connection: connection) end |
#connection(name = nil) ⇒ Object
26 27 28 29 |
# File 'lib/noiseless/dsl.rb', line 26 def connection(name = nil) @connection_name = name if name @connection_name || Noiseless.config.default_connection end |
#import ⇒ Object
36 37 38 |
# File 'lib/noiseless/dsl.rb', line 36 def import(*, **) BulkImporter.new(self).import(*, **) end |
#import_scoped(scope) ⇒ Object
40 41 42 |
# File 'lib/noiseless/dsl.rb', line 40 def import_scoped(scope, **) BulkImporter.new(self).import_scoped(scope, **) end |
#index_name(name = nil) ⇒ Object
11 12 13 14 |
# File 'lib/noiseless/dsl.rb', line 11 def index_name(name = nil) @index_name = name.to_s if name @index_name end |
#mapping(&block) ⇒ Object
31 32 33 34 |
# File 'lib/noiseless/dsl.rb', line 31 def mapping(&block) @mapping_block = block if block @mapping_block end |
#multi_search(models: nil, indexes: nil, connection: nil, &block) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/noiseless/dsl.rb', line 62 def multi_search(models: nil, indexes: nil, connection: nil, &block) search_instance = MultiSearch.new( models: models || [self], indexes: indexes, connection: connection || self.connection ) if block search_instance.search(&block) else search_instance end end |
#page(num = nil) ⇒ Object
76 77 78 |
# File 'lib/noiseless/dsl.rb', line 76 def page(num = nil) Pagination::SearchPaginator.new(self, page: num) end |
#per(num) ⇒ Object
80 81 82 |
# File 'lib/noiseless/dsl.rb', line 80 def per(num) Pagination::SearchPaginator.new(self, per_page: num) end |
#reindex ⇒ Object
44 45 46 |
# File 'lib/noiseless/dsl.rb', line 44 def reindex(**) BulkImporter.new(self).reindex(**) end |
#search_index(*names) ⇒ Object
6 7 8 9 |
# File 'lib/noiseless/dsl.rb', line 6 def search_index(*names) @index_names = names.flatten.map(&:to_s) if names.any? @index_names end |
#searchable ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/noiseless/dsl.rb', line 52 def searchable(**) include Callbacks unless included_modules.include?(Callbacks) include DSL::InstanceMethods unless included_modules.include?(DSL::InstanceMethods) auto_index(true, **) # Register the model in the global registry Noiseless.register_model(self, searchable: true, **) end |
#searchable_fields(*fields) ⇒ Object
16 17 18 19 |
# File 'lib/noiseless/dsl.rb', line 16 def searchable_fields(*fields) @searchable_fields = fields if fields.any? @searchable_fields end |