algoliasearch-rails 1.25.0 → 3.0.1
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 +4 -4
- data/CHANGELOG.MD +79 -1
- data/Gemfile +12 -38
- data/Gemfile.lock +157 -149
- data/README.md +13 -41
- data/algoliasearch-rails.gemspec +5 -5
- data/lib/algoliasearch/algolia_job.rb +1 -1
- data/lib/algoliasearch/configuration.rb +33 -4
- data/lib/algoliasearch/pagination/kaminari.rb +1 -1
- data/lib/algoliasearch/pagination/pagy.rb +29 -0
- data/lib/algoliasearch/pagination.rb +1 -0
- data/lib/algoliasearch/utilities.rb +1 -1
- data/lib/algoliasearch/version.rb +1 -1
- data/lib/algoliasearch-rails.rb +185 -207
- data/spec/spec_helper.rb +12 -5
- metadata +8 -14
- data/.travis.yml +0 -62
data/algoliasearch-rails.gemspec
CHANGED
@@ -21,7 +21,6 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.files = [
|
22
22
|
".document",
|
23
23
|
".rspec",
|
24
|
-
".travis.yml",
|
25
24
|
"CHANGELOG.MD",
|
26
25
|
"Gemfile",
|
27
26
|
"Gemfile.lock",
|
@@ -34,6 +33,7 @@ Gem::Specification.new do |s|
|
|
34
33
|
"lib/algoliasearch/configuration.rb",
|
35
34
|
"lib/algoliasearch/pagination.rb",
|
36
35
|
"lib/algoliasearch/pagination/kaminari.rb",
|
36
|
+
"lib/algoliasearch/pagination/pagy.rb",
|
37
37
|
"lib/algoliasearch/pagination/will_paginate.rb",
|
38
38
|
"lib/algoliasearch/railtie.rb",
|
39
39
|
"lib/algoliasearch/tasks/algoliasearch.rake",
|
@@ -79,19 +79,19 @@ Gem::Specification.new do |s|
|
|
79
79
|
|
80
80
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
81
81
|
s.add_runtime_dependency(%q<json>, [">= 1.5.1"])
|
82
|
-
s.add_runtime_dependency(%q<
|
82
|
+
s.add_runtime_dependency(%q<algolia>, [">= 3.5.2"])
|
83
83
|
s.add_development_dependency(%q<will_paginate>, [">= 2.3.15"])
|
84
84
|
s.add_development_dependency(%q<kaminari>, [">= 0"])
|
85
|
-
s.add_development_dependency "
|
85
|
+
s.add_development_dependency(%q<pagy>, [">= 0"])
|
86
86
|
s.add_development_dependency "rake"
|
87
87
|
s.add_development_dependency "rdoc"
|
88
88
|
else
|
89
89
|
s.add_dependency(%q<json>, [">= 1.5.1"])
|
90
|
-
s.add_dependency(%q<
|
90
|
+
s.add_dependency(%q<algolia>, [">= 3.5.2"])
|
91
91
|
end
|
92
92
|
else
|
93
93
|
s.add_dependency(%q<json>, [">= 1.5.1"])
|
94
|
-
s.add_dependency(%q<
|
94
|
+
s.add_dependency(%q<algolia>, [">= 3.5.2"])
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
@@ -1,14 +1,43 @@
|
|
1
1
|
module AlgoliaSearch
|
2
2
|
module Configuration
|
3
|
+
def initialize
|
4
|
+
@client = nil
|
5
|
+
end
|
6
|
+
|
3
7
|
def configuration
|
4
8
|
@@configuration || raise(NotConfigured, "Please configure AlgoliaSearch. Set AlgoliaSearch.configuration = {application_id: 'YOUR_APPLICATION_ID', api_key: 'YOUR_API_KEY'}")
|
5
9
|
end
|
6
10
|
|
7
11
|
def configuration=(configuration)
|
8
|
-
@@configuration =
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
+
@@configuration = default_configuration
|
13
|
+
.merge(configuration)
|
14
|
+
end
|
15
|
+
|
16
|
+
def client
|
17
|
+
if @client.nil?
|
18
|
+
setup_client
|
19
|
+
end
|
20
|
+
|
21
|
+
@client
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup_client
|
25
|
+
@client = Algolia::SearchClient.create(
|
26
|
+
@@configuration[:application_id],
|
27
|
+
@@configuration[:api_key],
|
28
|
+
{
|
29
|
+
user_agent_segments: [
|
30
|
+
"Algolia for Rails (#{AlgoliaSearch::VERSION})",
|
31
|
+
"Rails (#{defined?(::Rails::VERSION::STRING) ? ::Rails::VERSION::STRING : 'unknown'})",
|
32
|
+
@@configuration[:append_to_user_agent]
|
33
|
+
].compact
|
34
|
+
})
|
35
|
+
end
|
36
|
+
|
37
|
+
def default_configuration
|
38
|
+
{
|
39
|
+
queue_name: 'algoliasearch'
|
40
|
+
}
|
12
41
|
end
|
13
42
|
end
|
14
43
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
unless defined? Pagy
|
2
|
+
raise(AlgoliaSearch::BadConfiguration, "AlgoliaSearch: Please add 'pagy' to your Gemfile to use Pagy pagination backend")
|
3
|
+
end
|
4
|
+
|
5
|
+
module AlgoliaSearch
|
6
|
+
module Pagination
|
7
|
+
class Pagy
|
8
|
+
|
9
|
+
def self.create(results, total_hits, options = {})
|
10
|
+
vars = {
|
11
|
+
count: total_hits,
|
12
|
+
page: options[:page],
|
13
|
+
items: options[:per_page]
|
14
|
+
}
|
15
|
+
|
16
|
+
pagy_version = Gem::Version.new(::Pagy::VERSION)
|
17
|
+
pagy = if pagy_version >= Gem::Version.new('9.0')
|
18
|
+
::Pagy.new(**vars)
|
19
|
+
else
|
20
|
+
::Pagy.new(vars)
|
21
|
+
end
|
22
|
+
|
23
|
+
[pagy, results]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
@@ -3,6 +3,7 @@ module AlgoliaSearch
|
|
3
3
|
|
4
4
|
autoload :WillPaginate, 'algoliasearch/pagination/will_paginate'
|
5
5
|
autoload :Kaminari, 'algoliasearch/pagination/kaminari'
|
6
|
+
autoload :Pagy, 'algoliasearch/pagination/pagy'
|
6
7
|
|
7
8
|
def self.create(results, total_hits, options = {})
|
8
9
|
return results if AlgoliaSearch.configuration[:pagination_backend].nil?
|
@@ -2,7 +2,7 @@ module AlgoliaSearch
|
|
2
2
|
module Utilities
|
3
3
|
class << self
|
4
4
|
def get_model_classes
|
5
|
-
if defined?(Rails.autoloaders) && Rails.autoloaders.zeitwerk_enabled?
|
5
|
+
if Rails.application && defined?(Rails.autoloaders) && Rails.autoloaders.zeitwerk_enabled?
|
6
6
|
Zeitwerk::Loader.eager_load_all
|
7
7
|
elsif Rails.application
|
8
8
|
Rails.application.eager_load!
|