meilisearch-rails 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ad6c51de59755b283d9371028f127537f8eae862603d65469f3867e7e62b6ec
4
- data.tar.gz: a2ef9d38103f8e2750e687f1fae309818b210576b63c6951b913b7856c713598
3
+ metadata.gz: c0d3aeaf9f6e2549c11cdcd7cf5920fecb819fb1b2f03a25af11c19a5dd09444
4
+ data.tar.gz: 0af07156e3e3ea69d492745f806751e2213ad7148553f57396528ad54fa3f02a
5
5
  SHA512:
6
- metadata.gz: 5720f087c6c85aa34b553ba01614968fe4862a416c6e72c1829b4107470862a30db4e4107455d2a45ab94497ff69b084460196f6173c4f584aa1364769a0564a
7
- data.tar.gz: 5cebff7daa2d2caf3ed62e9a49fe4f3f17d4ccf2b6dcfed90f92645fdac4c7d8adddea521aff563aca9f454942529b1444c9fea092fd329e2cfda187ef885eba
6
+ metadata.gz: a49c6d3b48de31033515e61c9fd182842d5d7d7ba90e140b6447339eeb6473139f3de4f1c3428f48a9176f3c36c5080ebc198897f4b53900f74e416bb817eaf1
7
+ data.tar.gz: 63805d38ba88e0b020a0a147cce244ec35a0fb2a93715ff5b62df77ca87021b2b11581647626b2c76eaddc26ad15ab0a8e9d4e82c7e1895095829b7cce74965c
data/Gemfile CHANGED
@@ -1,14 +1,13 @@
1
- source 'http://rubygems.org'
1
+ source 'https://rubygems.org'
2
2
 
3
- gem 'json', '~> 2.5', '>= 2.5.1'
4
- gem 'meilisearch', '~> 0.18.0'
3
+ gemspec
5
4
 
6
5
  gem 'rubysl', '~> 2.0', platform: :rbx if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
7
6
 
8
7
  group :development do
9
- gem 'rubocop', '~> 1.22'
10
- gem 'rubocop-rails'
11
- gem 'rubocop-rspec'
8
+ gem 'rubocop', '1.27.0'
9
+ gem 'rubocop-rails', '2.13.2'
10
+ gem 'rubocop-rspec', '2.9.0'
12
11
  end
13
12
 
14
13
  group :test do
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Meilisearch
3
+ Copyright (c) 2021-2022 Meili SAS
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -58,7 +58,7 @@ To learn more about Meilisearch, check out our [Documentation](https://docs.meil
58
58
 
59
59
  ## 🤖 Compatibility with Meilisearch
60
60
 
61
- This package only guarantees the compatibility with the [version v0.25.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.25.0).
61
+ This package only guarantees the compatibility with the [version v0.27.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.27.0).
62
62
 
63
63
  ## 🔧 Installation <!-- omit in toc -->
64
64
 
@@ -84,7 +84,7 @@ For example, if you use Docker:
84
84
 
85
85
  ```bash
86
86
  docker pull getmeili/meilisearch:latest # Fetch the latest version of Meilisearch image from Docker Hub
87
- docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest ./meilisearch --master-key=masterKey
87
+ docker run -it --rm -p 7700:7700 getmeili/meilisearch:latest meilisearch --master-key=masterKey
88
88
  ```
89
89
 
90
90
  NB: you can also download Meilisearch from **Homebrew** or **APT**.
@@ -170,10 +170,10 @@ Then, as soon as you use the `search` method, the returning results will be pagi
170
170
  <%= will_paginate @hits %> # if using will_paginate
171
171
  ```
172
172
 
173
- The **number of hits per page defaults to 20**, you can customize it by adding the `hitsPerPage` parameter to your search:
173
+ The **number of hits per page defaults to 20**, you can customize it by adding the `hits_per_page` parameter to your search:
174
174
 
175
175
  ```ruby
176
- Book.search('harry potter', hitsPerPage: 10)
176
+ Book.search('harry potter', hits_per_page: 10)
177
177
  ```
178
178
 
179
179
  #### Extra Configuration <!-- omit in toc -->
@@ -228,7 +228,7 @@ Check the dedicated section of the documentation, for more information on the [s
228
228
  All the supported options are described in the [search parameters](https://docs.meilisearch.com/reference/features/search_parameters.html) section of the documentation.
229
229
 
230
230
  ```ruby
231
- Book.search('Harry', attributesToHighlight: ['*'])
231
+ Book.search('Harry', attributes_to_highlight: ['*'])
232
232
  ```
233
233
  👉 Don't forget that `attributes_to_highlight`, `attributes_to_crop`, and
234
234
  `crop_length` can be set up in the `meilisearch` block of your model.
@@ -256,24 +256,36 @@ By default, the **index_uid** will be the class name, e.g. `Book`. You can custo
256
256
  class Book < ActiveRecord::Base
257
257
  include MeiliSearch::Rails
258
258
 
259
- meilisearch index_uid: 'MyCustomUID' do
260
- end
259
+ meilisearch index_uid: 'MyCustomUID'
261
260
  end
262
261
  ```
263
262
 
264
263
  #### Index UID according to the environment <!-- omit in toc -->
265
264
 
266
- You can suffix the index UID with the current Rails environment using the following option:
265
+ You can suffix the index UID with the current Rails environment using one of the following options:
266
+
267
+ By defining directly in your model:
267
268
 
268
269
  ```ruby
269
270
  class Book < ActiveRecord::Base
270
271
  include MeiliSearch::Rails
271
272
 
272
- meilisearch per_environment: true do # The index UID will be "Book_#{Rails.env}"
273
- end
273
+ meilisearch per_environment: true
274
274
  end
275
275
  ```
276
276
 
277
+ Or setting it globally:
278
+
279
+ ```ruby
280
+ MeiliSearch::Rails.configuration = {
281
+ meilisearch_host: 'YourMeilisearchHost',
282
+ meilisearch_api_key: 'YourMeilisearchAPIKey',
283
+ per_environment: true
284
+ }
285
+ ```
286
+
287
+ Both options will make your index name look like this `"Book_#{Rails.env}"`.
288
+
277
289
  ### Index configuration
278
290
 
279
291
  #### Custom attribute definition
@@ -318,8 +330,7 @@ Note that the primary key must have a **unique value**.
318
330
  class Book < ActiveRecord::Base
319
331
  include MeiliSearch::Rails
320
332
 
321
- meilisearch primary_key: 'ISBN' do
322
- end
333
+ meilisearch primary_key: 'ISBN'
323
334
  end
324
335
  ```
325
336
  #### Conditional indexing
@@ -331,8 +342,7 @@ As soon as you use those constraints, `add_documents` and `delete_documents` cal
331
342
  class Book < ActiveRecord::Base
332
343
  include MeiliSearch::Rails
333
344
 
334
- meilisearch if: :published?, unless: :premium? do
335
- end
345
+ meilisearch if: :published?, unless: :premium?
336
346
 
337
347
  def published?
338
348
  # [...]
@@ -369,6 +379,7 @@ class Book < ActiveRecord::Base
369
379
  end
370
380
 
371
381
  private
382
+
372
383
  def public?
373
384
  released? && !premium?
374
385
  end
@@ -383,10 +394,10 @@ You may want to share an index between several models. You'll need to ensure you
383
394
  class Cat < ActiveRecord::Base
384
395
  include MeiliSearch::Rails
385
396
 
386
- meilisearch index_uid: 'Animals', primary_key: :ms_id do
387
- end
397
+ meilisearch index_uid: 'Animals', primary_key: :ms_id
388
398
 
389
399
  private
400
+
390
401
  def ms_id
391
402
  "cat_#{primary_key}" # ensure the cats & dogs primary_keys are not conflicting
392
403
  end
@@ -395,10 +406,10 @@ end
395
406
  class Dog < ActiveRecord::Base
396
407
  include MeiliSearch::Rails
397
408
 
398
- meilisearch index_uid: 'Animals', primary_key: :ms_id do
399
- end
409
+ meilisearch index_uid: 'Animals', primary_key: :ms_id
400
410
 
401
411
  private
412
+
402
413
  def ms_id
403
414
  "dog_#{primary_key}" # ensure the cats & dogs primary_keys are not conflicting
404
415
  end
@@ -413,8 +424,7 @@ You can configure the auto-indexing & auto-removal process to use a queue to per
413
424
  class Book < ActiveRecord::Base
414
425
  include MeiliSearch::Rails
415
426
 
416
- meilisearch enqueue: true do # ActiveJob will be triggered using a `meilisearch` queue
417
- end
427
+ meilisearch enqueue: true # ActiveJob will be triggered using a `meilisearch` queue
418
428
  end
419
429
  ```
420
430
 
@@ -458,16 +468,16 @@ With [**Sidekiq**](https://github.com/mperham/sidekiq):
458
468
  class Book < ActiveRecord::Base
459
469
  include MeiliSearch::Rails
460
470
 
461
- meilisearch enqueue: :trigger_sidekiq_worker do
471
+ meilisearch enqueue: :trigger_sidekiq_job do
462
472
  attribute :title, :author, :description
463
473
  end
464
474
 
465
- def self.trigger_sidekiq_worker(record, remove)
466
- MySidekiqWorker.perform_async(record.id, remove)
475
+ def self.trigger_sidekiq_job(record, remove)
476
+ MySidekiqJob.perform_async(record.id, remove)
467
477
  end
468
478
  end
469
479
 
470
- class MySidekiqWorker
480
+ class MySidekiqJob
471
481
  def perform(id, remove)
472
482
  if remove
473
483
  # The record has likely already been removed from your database so we cannot
@@ -586,8 +596,7 @@ You can strip all HTML tags from your attributes with the `sanitize` option.
586
596
  class Book < ActiveRecord::Base
587
597
  include MeiliSearch::Rails
588
598
 
589
- meilisearch sanitize: true do
590
- end
599
+ meilisearch sanitize: true
591
600
  end
592
601
  ```
593
602
 
@@ -599,8 +608,7 @@ You can force the UTF-8 encoding of all your attributes using the `force_utf8_en
599
608
  class Book < ActiveRecord::Base
600
609
  include MeiliSearch::Rails
601
610
 
602
- meilisearch force_utf8_encoding: true do
603
- end
611
+ meilisearch force_utf8_encoding: true
604
612
  end
605
613
  ```
606
614
 
@@ -652,8 +660,7 @@ class Book < ActiveRecord::Base
652
660
  include MeiliSearch::Rails
653
661
 
654
662
  # Only raise exceptions in development environment.
655
- meilisearch raise_on_failure: Rails.env.development? do
656
- end
663
+ meilisearch raise_on_failure: Rails.env.development?
657
664
  end
658
665
  ```
659
666
 
@@ -667,8 +674,7 @@ You can force indexing and removing to be synchronous by setting the following o
667
674
  class Book < ActiveRecord::Base
668
675
  include MeiliSearch::Rails
669
676
 
670
- meilisearch synchronous: true do
671
- end
677
+ meilisearch synchronous: true
672
678
  end
673
679
  ```
674
680
  🚨 This is only recommended for testing purposes, the gem will call the `wait_for_task` method that will stop your code execution until the asynchronous task has been processed by MeilSearch.
@@ -681,8 +687,7 @@ You can disable auto-indexing and auto-removing setting the following options:
681
687
  class Book < ActiveRecord::Base
682
688
  include MeiliSearch::Rails
683
689
 
684
- meilisearch auto_index: false, auto_remove: false do
685
- end
690
+ meilisearch auto_index: false, auto_remove: false
686
691
  end
687
692
  ```
688
693
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module MeiliSearch
4
4
  module Rails
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
@@ -105,7 +105,7 @@ module MeiliSearch
105
105
  end
106
106
 
107
107
  def sequel?(document)
108
- defined?(::Sequel) && document.class < ::Sequel::Model
108
+ defined?(::Sequel::Model) && document.class < ::Sequel::Model
109
109
  end
110
110
 
111
111
  def active_record?(document)
@@ -224,7 +224,7 @@ module MeiliSearch
224
224
  if defined?(::ActiveJob::Base)
225
225
  # lazy load the ActiveJob class to ensure the
226
226
  # queue is initialized before using it
227
- autoload :MSJob, 'meilisearch/ms_job'
227
+ autoload :MSJob, 'meilisearch/rails/ms_job'
228
228
  end
229
229
 
230
230
  # this class wraps an MeiliSearch::Index document ensuring all raised exceptions
@@ -319,8 +319,12 @@ module MeiliSearch
319
319
 
320
320
  attr_accessor :formatted
321
321
 
322
+ if options.key?(:per_environment)
323
+ raise BadConfiguration, ':per_environment option should be defined globally on MeiliSearch::Rails.configuration block.'
324
+ end
325
+
322
326
  if options[:synchronous] == true
323
- if defined?(::Sequel) && self < Sequel::Model
327
+ if defined?(::Sequel::Model) && self < Sequel::Model
324
328
  class_eval do
325
329
  copy_after_validation = instance_method(:after_validation)
326
330
  define_method(:after_validation) do |*args|
@@ -352,7 +356,7 @@ module MeiliSearch
352
356
  end
353
357
  end
354
358
  unless options[:auto_index] == false
355
- if defined?(::Sequel) && self < Sequel::Model
359
+ if defined?(::Sequel::Model) && self < Sequel::Model
356
360
  class_eval do
357
361
  copy_after_validation = instance_method(:after_validation)
358
362
  copy_before_save = instance_method(:before_save)
@@ -399,7 +403,7 @@ module MeiliSearch
399
403
  end
400
404
  end
401
405
  unless options[:auto_remove] == false
402
- if defined?(::Sequel) && self < Sequel::Model
406
+ if defined?(::Sequel::Model) && self < Sequel::Model
403
407
  class_eval do
404
408
  copy_after_destroy = instance_method(:after_destroy)
405
409
 
@@ -653,8 +657,11 @@ module MeiliSearch
653
657
 
654
658
  def ms_index_uid(options = nil)
655
659
  options ||= meilisearch_options
660
+ global_options ||= MeiliSearch::Rails.configuration
661
+
656
662
  name = options[:index_uid] || model_name.to_s.gsub('::', '_')
657
- name = "#{name}_#{::Rails.env}" if options[:per_environment]
663
+ name = "#{name}_#{::Rails.env}" if global_options[:per_environment]
664
+
658
665
  name
659
666
  end
660
667
 
@@ -674,6 +681,7 @@ module MeiliSearch
674
681
  [options[:if], options[:unless]].each do |condition|
675
682
  case condition
676
683
  when nil
684
+ return false
677
685
  when String, Symbol
678
686
  return true if ms_attribute_changed?(document, condition)
679
687
  else
@@ -820,7 +828,7 @@ module MeiliSearch
820
828
  def ms_find_in_batches(batch_size, &block)
821
829
  if (defined?(::ActiveRecord) && ancestors.include?(::ActiveRecord::Base)) || respond_to?(:find_in_batches)
822
830
  find_in_batches(batch_size: batch_size, &block)
823
- elsif defined?(::Sequel) && self < Sequel::Model
831
+ elsif defined?(::Sequel::Model) && self < Sequel::Model
824
832
  dataset.extension(:pagination).each_page(batch_size, &block)
825
833
  else
826
834
  # don't worry, mongoid has its own underlying cursor/streaming mechanism
@@ -902,7 +910,7 @@ module MeiliSearch
902
910
  # ms_must_reindex flag is reset after every commit as part. If we must reindex at any point in
903
911
  # a transaction, keep flag set until it is explicitly unset
904
912
  @ms_must_reindex ||=
905
- if defined?(::Sequel) && is_a?(Sequel::Model)
913
+ if defined?(::Sequel::Model) && is_a?(Sequel::Model)
906
914
  new? || self.class.ms_must_reindex?(self)
907
915
  else
908
916
  new_record? || self.class.ms_must_reindex?(self)
@@ -1,19 +1,21 @@
1
- require File.join(File.dirname(__FILE__), 'lib', 'meilisearch', 'rails', 'version')
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
2
3
 
3
- require 'date'
4
+ require 'meilisearch/rails/version'
4
5
 
5
6
  Gem::Specification.new do |s|
6
7
  s.name = 'meilisearch-rails'
7
8
  s.version = MeiliSearch::Rails::VERSION
8
9
 
9
- s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
10
10
  s.authors = ['Meili']
11
- s.description = 'Meilisearch integration for Ruby on Rails. See https://github.com/meilisearch/meilisearch'
12
11
  s.email = 'bonjour@meilisearch.com'
13
- s.homepage = 'http://github.com/meilisearch/meilisearch-rails'
14
- s.licenses = ['MIT']
15
- s.require_paths = ['lib']
12
+
13
+ s.description = 'Meilisearch integration for Ruby on Rails. See https://github.com/meilisearch/meilisearch'
14
+ s.homepage = 'https://github.com/meilisearch/meilisearch-rails'
16
15
  s.summary = 'Meilisearch integration for Ruby on Rails.'
16
+ s.licenses = 'MIT'
17
+
18
+ s.require_paths = ['lib']
17
19
 
18
20
  s.extra_rdoc_files = [
19
21
  'LICENSE',
@@ -31,6 +33,6 @@ Gem::Specification.new do |s|
31
33
  ]
32
34
 
33
35
  s.required_ruby_version = '>= 2.6.0'
34
- s.add_dependency('json', ['>= 1.5.1'])
35
- s.add_dependency('meilisearch', ['>= 0.15.4'])
36
+
37
+ s.add_dependency 'meilisearch', '~> 0.18'
36
38
  end
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meilisearch-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Meili
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-02-08 00:00:00.000000000 Z
11
+ date: 2022-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: json
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 1.5.1
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 1.5.1
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: meilisearch
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - ">="
17
+ - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: 0.15.4
19
+ version: '0.18'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - ">="
24
+ - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: 0.15.4
26
+ version: '0.18'
41
27
  description: Meilisearch integration for Ruby on Rails. See https://github.com/meilisearch/meilisearch
42
28
  email: bonjour@meilisearch.com
43
29
  executables: []
@@ -63,7 +49,7 @@ files:
63
49
  - lib/meilisearch/rails/utilities.rb
64
50
  - lib/meilisearch/rails/version.rb
65
51
  - meilisearch-rails.gemspec
66
- homepage: http://github.com/meilisearch/meilisearch-rails
52
+ homepage: https://github.com/meilisearch/meilisearch-rails
67
53
  licenses:
68
54
  - MIT
69
55
  metadata: {}