about summary refs log tree commit diff
path: root/config/initializers/chewy.rb
diff options
context:
space:
mode:
Diffstat (limited to 'config/initializers/chewy.rb')
-rw-r--r--config/initializers/chewy.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/config/initializers/chewy.rb b/config/initializers/chewy.rb
new file mode 100644
index 000000000..bef2746ec
--- /dev/null
+++ b/config/initializers/chewy.rb
@@ -0,0 +1,22 @@
+enabled         = ENV['ES_ENABLED'] == 'true'
+host            = ENV.fetch('ES_HOST') { 'localhost' }
+port            = ENV.fetch('ES_PORT') { 9200 }
+fallback_prefix = ENV.fetch('REDIS_NAMESPACE') { nil }
+prefix          = ENV.fetch('ES_PREFIX') { fallback_prefix }
+
+Chewy.settings = {
+  host: "#{host}:#{port}",
+  prefix: prefix,
+  enabled: enabled,
+  journal: false,
+}
+
+Chewy.root_strategy = enabled ? :sidekiq : :bypass
+
+module Chewy
+  class << self
+    def enabled?
+      settings[:enabled]
+    end
+  end
+end