Commit 7def99b65ddf0737c3221e710fec3a513542ea89
1 parent
e3a4f7ee
Exists in
master
and in
21 other branches
Label as private
Showing
1 changed file
with
11 additions
and
12 deletions
Show diff stats
lib/searchkick.rb
... | ... | @@ -28,12 +28,8 @@ module Searchkick |
28 | 28 | class ImportError < Error; end |
29 | 29 | |
30 | 30 | class << self |
31 | - attr_accessor :search_method_name | |
32 | - attr_accessor :wordnet_path | |
33 | - attr_accessor :timeout | |
34 | - attr_writer :search_timeout | |
35 | - attr_accessor :models | |
36 | - attr_writer :env | |
31 | + attr_accessor :search_method_name, :wordnet_path, :timeout, :models | |
32 | + attr_writer :client, :env, :search_timeout | |
37 | 33 | end |
38 | 34 | self.search_method_name = :search |
39 | 35 | self.wordnet_path = "/var/lib/wn_s.pl" |
... | ... | @@ -50,8 +46,8 @@ module Searchkick |
50 | 46 | end |
51 | 47 | end |
52 | 48 | |
53 | - class << self | |
54 | - attr_writer :client | |
49 | + def self.env | |
50 | + @env ||= ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development" | |
55 | 51 | end |
56 | 52 | |
57 | 53 | def self.search_timeout |
... | ... | @@ -89,17 +85,20 @@ module Searchkick |
89 | 85 | end |
90 | 86 | end |
91 | 87 | |
88 | + # private | |
92 | 89 | def self.queue_items(items) |
93 | 90 | queued_items.concat(items) |
94 | 91 | perform_bulk unless callbacks_value == :bulk |
95 | 92 | end |
96 | 93 | |
94 | + # private | |
97 | 95 | def self.perform_bulk |
98 | 96 | items = queued_items |
99 | 97 | clear_queued_items |
100 | 98 | perform_items(items) |
101 | 99 | end |
102 | 100 | |
101 | + # private | |
103 | 102 | def self.perform_items(items) |
104 | 103 | if items.any? |
105 | 104 | response = client.bulk(body: items) |
... | ... | @@ -110,25 +109,25 @@ module Searchkick |
110 | 109 | end |
111 | 110 | end |
112 | 111 | |
112 | + # private | |
113 | 113 | def self.queued_items |
114 | 114 | Thread.current[:searchkick_queued_items] ||= [] |
115 | 115 | end |
116 | 116 | |
117 | + # private | |
117 | 118 | def self.clear_queued_items |
118 | 119 | Thread.current[:searchkick_queued_items] = [] |
119 | 120 | end |
120 | 121 | |
122 | + # private | |
121 | 123 | def self.callbacks_value |
122 | 124 | Thread.current[:searchkick_callbacks_enabled] |
123 | 125 | end |
124 | 126 | |
127 | + # private | |
125 | 128 | def self.callbacks_value=(value) |
126 | 129 | Thread.current[:searchkick_callbacks_enabled] = value |
127 | 130 | end |
128 | - | |
129 | - def self.env | |
130 | - @env ||= ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development" | |
131 | - end | |
132 | 131 | end |
133 | 132 | |
134 | 133 | # TODO find better ActiveModel hook | ... | ... |