meilisearch-rails 0.2.3 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,46 +1,36 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require File.join(File.dirname(__FILE__), 'lib', 'meilisearch', 'version')
1
+ require File.join(File.dirname(__FILE__), 'lib', 'meilisearch', 'rails', 'version')
4
2
 
5
3
  require 'date'
6
4
 
7
5
  Gem::Specification.new do |s|
8
- s.name = "meilisearch-rails"
9
- s.version = MeiliSearch::VERSION
6
+ s.name = 'meilisearch-rails'
7
+ s.version = MeiliSearch::Rails::VERSION
8
+
9
+ s.required_rubygems_version = Gem::Requirement.new('>= 0') if s.respond_to? :required_rubygems_version=
10
+ s.authors = ['Meili']
11
+ s.description = 'Meilisearch integration for Ruby on Rails. See https://github.com/meilisearch/meilisearch'
12
+ s.email = 'bonjour@meilisearch.com'
13
+ s.homepage = 'http://github.com/meilisearch/meilisearch-rails'
14
+ s.licenses = ['MIT']
15
+ s.require_paths = ['lib']
16
+ s.summary = 'Meilisearch integration for Ruby on Rails.'
10
17
 
11
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
- s.authors = ["Meili"]
13
- s.date = Date.today
14
- s.description = "MeiliSearch integration for Ruby on Rails. See https://github.com/meilisearch/MeiliSearch"
15
- s.email = "bonjour@meilisearch.com"
16
18
  s.extra_rdoc_files = [
17
- "LICENSE",
18
- "README.md"
19
+ 'LICENSE',
20
+ 'README.md'
19
21
  ]
20
- s.files = [
21
- ".rspec",
22
- "Gemfile",
23
- "LICENSE",
24
- "README.md",
25
- "Rakefile",
26
- "meilisearch-rails.gemspec",
27
- "lib/meilisearch-rails.rb",
28
- "lib/meilisearch/ms_job.rb",
29
- "lib/meilisearch/configuration.rb",
30
- "lib/meilisearch/pagination.rb",
31
- "lib/meilisearch/pagination/kaminari.rb",
32
- "lib/meilisearch/pagination/will_paginate.rb",
33
- "lib/meilisearch/railtie.rb",
34
- "lib/meilisearch/tasks/meilisearch.rake",
35
- "lib/meilisearch/utilities.rb",
36
- "lib/meilisearch/version.rb",
37
- "spec/spec_helper.rb",
38
- "spec/utilities_spec.rb"
22
+
23
+ s.files = Dir[
24
+ 'lib/**/*',
25
+ '.rspec',
26
+ 'meilisearch-rails.gemspec',
27
+ 'Gemfile',
28
+ 'LICENSE',
29
+ 'README.md',
30
+ 'Rakefile'
39
31
  ]
40
- s.homepage = "http://github.com/meilisearch/meilisearch-rails"
41
- s.licenses = ["MIT"]
42
- s.require_paths = ["lib"]
43
- s.summary = "MeiliSearch integration for Ruby on Rails."
44
- s.add_dependency("json", [">= 1.5.1"])
45
- s.add_dependency("meilisearch", [">= 0.15.4"])
32
+
33
+ s.required_ruby_version = '>= 2.6.0'
34
+ s.add_dependency('json', ['>= 1.5.1'])
35
+ s.add_dependency('meilisearch', ['>= 0.15.4'])
46
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meilisearch-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Meili
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-26 00:00:00.000000000 Z
11
+ date: 2022-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.15.4
41
- description: MeiliSearch integration for Ruby on Rails. See https://github.com/meilisearch/MeiliSearch
41
+ description: Meilisearch integration for Ruby on Rails. See https://github.com/meilisearch/meilisearch
42
42
  email: bonjour@meilisearch.com
43
43
  executables: []
44
44
  extensions: []
@@ -52,18 +52,17 @@ files:
52
52
  - README.md
53
53
  - Rakefile
54
54
  - lib/meilisearch-rails.rb
55
- - lib/meilisearch/configuration.rb
56
- - lib/meilisearch/ms_job.rb
57
- - lib/meilisearch/pagination.rb
58
- - lib/meilisearch/pagination/kaminari.rb
59
- - lib/meilisearch/pagination/will_paginate.rb
60
- - lib/meilisearch/railtie.rb
61
- - lib/meilisearch/tasks/meilisearch.rake
62
- - lib/meilisearch/utilities.rb
63
- - lib/meilisearch/version.rb
55
+ - lib/meilisearch/rails/configuration.rb
56
+ - lib/meilisearch/rails/errors.rb
57
+ - lib/meilisearch/rails/ms_job.rb
58
+ - lib/meilisearch/rails/pagination.rb
59
+ - lib/meilisearch/rails/pagination/kaminari.rb
60
+ - lib/meilisearch/rails/pagination/will_paginate.rb
61
+ - lib/meilisearch/rails/railtie.rb
62
+ - lib/meilisearch/rails/tasks/meilisearch.rake
63
+ - lib/meilisearch/rails/utilities.rb
64
+ - lib/meilisearch/rails/version.rb
64
65
  - meilisearch-rails.gemspec
65
- - spec/spec_helper.rb
66
- - spec/utilities_spec.rb
67
66
  homepage: http://github.com/meilisearch/meilisearch-rails
68
67
  licenses:
69
68
  - MIT
@@ -76,7 +75,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
75
  requirements:
77
76
  - - ">="
78
77
  - !ruby/object:Gem::Version
79
- version: '0'
78
+ version: 2.6.0
80
79
  required_rubygems_version: !ruby/object:Gem::Requirement
81
80
  requirements:
82
81
  - - ">="
@@ -86,5 +85,5 @@ requirements: []
86
85
  rubygems_version: 3.0.3.1
87
86
  signing_key:
88
87
  specification_version: 4
89
- summary: MeiliSearch integration for Ruby on Rails.
88
+ summary: Meilisearch integration for Ruby on Rails.
90
89
  test_files: []
@@ -1,19 +0,0 @@
1
- module MeiliSearch
2
- module Configuration
3
- def configuration
4
- @@configuration || raise(NotConfigured, "Please configure MeiliSearch. Set MeiliSearch.configuration = {meilisearch_host: 'YOUR_MEILISEARCH_HOST', meilisearch_api_key: 'YOUR_API_KEY'}")
5
- end
6
-
7
- def configuration=(configuration)
8
- @@configuration = configuration
9
- end
10
-
11
- def client
12
- ::MeiliSearch::Client.new(
13
- configuration[:meilisearch_host],
14
- configuration[:meilisearch_api_key],
15
- configuration.slice(:timeout, :max_retries)
16
- )
17
- end
18
- end
19
- end
@@ -1,9 +0,0 @@
1
- module MeiliSearch
2
- class MSJob < ::ActiveJob::Base
3
- queue_as :meilisearch
4
-
5
- def perform(record, method)
6
- record.send(method)
7
- end
8
- end
9
- end
@@ -1,44 +0,0 @@
1
- unless defined? Kaminari
2
- raise(MeiliSearch::BadConfiguration, "MeiliSearch: Please add 'kaminari' to your Gemfile to use kaminari pagination backend")
3
- end
4
-
5
- require "kaminari/models/array_extension"
6
-
7
- module MeiliSearch
8
- module Pagination
9
- class Kaminari < ::Kaminari::PaginatableArray
10
-
11
- def initialize(array, options)
12
- if RUBY_VERSION >= '3'
13
- super(array, **options)
14
- else
15
- super(array, options)
16
- end
17
- end
18
-
19
- def limit(num)
20
- # noop
21
- self
22
- end
23
-
24
- def offset(num)
25
- # noop
26
- self
27
- end
28
-
29
- class << self
30
- def create(results, total_hits, options = {})
31
- offset = ((options[:page] - 1) * options[:per_page])
32
- array = new results, limit: options[:per_page], offset: offset, total_count: total_hits
33
- if array.empty? and !results.empty?
34
- # since Kaminari 0.16.0, you need to pad the results with nil values so it matches the offset param
35
- # otherwise you'll get an empty array: https://github.com/amatsuda/kaminari/commit/29fdcfa8865f2021f710adaedb41b7a7b081e34d
36
- results = ([nil] * offset) + results
37
- array = new results, offset: offset, limit: options[:per_page], total_count: total_hits
38
- end
39
- array
40
- end
41
- end
42
- end
43
- end
44
- end
@@ -1,19 +0,0 @@
1
- begin
2
- require 'will_paginate/collection'
3
- rescue LoadError
4
- raise(MeiliSearch::BadConfiguration, "MeiliSearch: Please add 'will_paginate' to your Gemfile to use will_paginate pagination backend")
5
- end
6
-
7
- module MeiliSearch
8
- module Pagination
9
- class WillPaginate
10
- def self.create(results, total_hits, options = {})
11
- ::WillPaginate::Collection.create(options[:page], options[:per_page], total_hits) do |pager|
12
- start = (options[:page] - 1) * options[:per_page]
13
- paginated_results = results[start, options[:per_page]]
14
- pager.replace paginated_results
15
- end
16
- end
17
- end
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- module MeiliSearch
2
- module Pagination
3
-
4
- autoload :WillPaginate, 'meilisearch/pagination/will_paginate'
5
- autoload :Kaminari, 'meilisearch/pagination/kaminari'
6
-
7
- def self.create(results, total_hits, options = {})
8
- return results if MeiliSearch.configuration[:pagination_backend].nil?
9
- begin
10
- backend = MeiliSearch.configuration[:pagination_backend].to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase } # classify pagination backend name
11
- page = Object.const_get(:MeiliSearch).const_get(:Pagination).const_get(backend).create(results, total_hits, options)
12
- page
13
- rescue NameError
14
- raise(BadConfiguration, "Unknown pagination backend")
15
- end
16
- end
17
-
18
- end
19
- end
@@ -1,11 +0,0 @@
1
- require 'rails'
2
-
3
- module MeiliSearch
4
- class Railtie < Rails::Railtie
5
- rake_tasks do
6
- load "meilisearch/tasks/meilisearch.rake"
7
- end
8
- end
9
- class Engine < Rails::Engine
10
- end
11
- end
@@ -1,19 +0,0 @@
1
- namespace :meilisearch do
2
-
3
- desc "Reindex all models"
4
- task :reindex => :environment do
5
- MeiliSearch::Utilities.reindex_all_models
6
- end
7
-
8
- desc "Set settings to all indexes"
9
- task :set_all_settings => :environment do
10
- MeiliSearch::Utilities.set_settings_all_models
11
- end
12
-
13
- desc "Clear all indexes"
14
- task :clear_indexes => :environment do
15
- puts "clearing all indexes"
16
- MeiliSearch::Utilities.clear_all_indexes
17
- end
18
-
19
- end
@@ -1,49 +0,0 @@
1
- module MeiliSearch
2
- module Utilities
3
- class << self
4
- def get_model_classes
5
- if Rails.application && defined?(Rails.autoloaders) && Rails.autoloaders.zeitwerk_enabled?
6
- Zeitwerk::Loader.eager_load_all
7
- elsif Rails.application
8
- Rails.application.eager_load!
9
- end
10
- klasses = MeiliSearch.instance_variable_get(:@included_in)
11
- (klasses + klasses.map{ |klass| klass.descendants }.flatten).uniq
12
- end
13
-
14
- def clear_all_indexes
15
- get_model_classes.each do |klass|
16
- klass.clear_index!
17
- end
18
- end
19
-
20
- def reindex_all_models
21
- klasses = get_model_classes
22
-
23
- puts ''
24
- puts "Reindexing #{klasses.count} models: #{klasses.to_sentence}."
25
- puts ''
26
-
27
- klasses.each do |klass|
28
- puts klass
29
- puts "Reindexing #{klass.count} records..."
30
- klass.ms_reindex!
31
- end
32
- end
33
-
34
- def set_settings_all_models
35
- klasses = get_model_classes
36
-
37
- puts ''
38
- puts "Pushing settings for #{klasses.count} models: #{klasses.to_sentence}."
39
- puts ''
40
-
41
- klasses.each do |klass|
42
- puts "Pushing #{klass} settings..."
43
- klass.ms_set_settings
44
- end
45
- end
46
- end
47
- end
48
- end
49
-
@@ -1,3 +0,0 @@
1
- module MeiliSearch
2
- VERSION = '0.2.3'
3
- end
data/spec/spec_helper.rb DELETED
@@ -1,52 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- require 'timeout'
4
- require 'dotenv/load'
5
- require 'faker'
6
- Bundler.setup :test
7
-
8
- $LOAD_PATH.unshift(File.dirname(__FILE__))
9
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
-
11
- require 'meilisearch-rails'
12
- require 'rspec'
13
- require 'rails/all'
14
-
15
- raise "missing MEILISEARCH_HOST or MEILISEARCH_API_KEY environment variables" if ENV['MEILISEARCH_HOST'].nil? || ENV['MEILISEARCH_API_KEY'].nil?
16
-
17
- Thread.current[:meilisearch_hosts] = nil
18
-
19
- RSpec.configure do |c|
20
- c.mock_with :rspec
21
- c.filter_run focus: true
22
- c.run_all_when_everything_filtered = true
23
- c.formatter = 'documentation'
24
-
25
- c.around(:each) do |example|
26
- Timeout::timeout(120) {
27
- example.run
28
- }
29
- end
30
-
31
- # Remove all indexes setup in this run in local or CI
32
- c.after(:suite) do
33
- safe_index_list.each do |index|
34
- MeiliSearch.client.delete_index(index['name'])
35
- end
36
- end
37
- end
38
-
39
- # A unique prefix for your test run in local or CI
40
- SAFE_INDEX_PREFIX = "rails_#{SecureRandom.hex(8)}".freeze
41
-
42
- # avoid concurrent access to the same index in local or CI
43
- def safe_index_uid(name)
44
- "#{SAFE_INDEX_PREFIX}_#{name}"
45
- end
46
-
47
- # get a list of safe indexes in local or CI
48
- def safe_index_list
49
- list = MeiliSearch.client.indexes()
50
- list = list.select { |index| index["name"].include?(SAFE_INDEX_PREFIX) }
51
- list.sort_by { |index| index["primary"] || "" }
52
- end
@@ -1,36 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper'))
2
-
3
- MeiliSearch.configuration = { meilisearch_host: ENV['MEILISEARCH_HOST'], meilisearch_api_key: ENV['MEILISEARCH_API_KEY'] }
4
-
5
- describe MeiliSearch::Utilities do
6
-
7
- before(:each) do
8
- @included_in = MeiliSearch.instance_variable_get :@included_in
9
- MeiliSearch.instance_variable_set :@included_in, []
10
-
11
- class Dummy
12
- include MeiliSearch
13
-
14
- def self.model_name
15
- "Dummy"
16
- end
17
-
18
- meilisearch
19
- end
20
-
21
- class DummyChild < Dummy
22
- end
23
-
24
- class DummyGrandChild < DummyChild
25
- end
26
- end
27
-
28
- after(:each) do
29
- MeiliSearch.instance_variable_set :@included_in, @included_in
30
- end
31
-
32
- it "should get the models where MeiliSearch module was included" do
33
- (MeiliSearch::Utilities.get_model_classes - [Dummy, DummyChild, DummyGrandChild]).should == []
34
- end
35
-
36
- end