Commit 514538593a350b2ec56ab77e789fd7936761c777

Authored by Andrew Kane
1 parent 21048dfa

Better env logic

CHANGELOG.md
... ... @@ -2,6 +2,7 @@
2 2  
3 3 - Added `boost_by_distance`
4 4 - More flexible highlight options
  5 +- Better `env` logic
5 6  
6 7 ## 0.8.3
7 8  
... ...
lib/searchkick.rb
... ... @@ -63,6 +63,10 @@ module Searchkick
63 63 def self.callbacks?
64 64 callbacks
65 65 end
  66 +
  67 + def self.env
  68 + @env ||= ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
  69 + end
66 70 end
67 71  
68 72 # TODO find better ActiveModel hook
... ...
lib/searchkick/model.rb
... ... @@ -5,15 +5,14 @@ module Searchkick
5 5 raise "Only call searchkick once per model" if respond_to?(:searchkick_index)
6 6  
7 7 class_eval do
8   - cattr_reader :searchkick_options, :searchkick_env, :searchkick_klass
  8 + cattr_reader :searchkick_options, :searchkick_klass
9 9  
10 10 callbacks = options.has_key?(:callbacks) ? options[:callbacks] : true
11 11  
12 12 class_variable_set :@@searchkick_options, options.dup
13   - class_variable_set :@@searchkick_env, ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development"
14 13 class_variable_set :@@searchkick_klass, self
15 14 class_variable_set :@@searchkick_callbacks, callbacks
16   - class_variable_set :@@searchkick_index, options[:index_name] || [options[:index_prefix], model_name.plural, searchkick_env].compact.join("_")
  15 + class_variable_set :@@searchkick_index, options[:index_name] || [options[:index_prefix], model_name.plural, Searchkick.env].compact.join("_")
17 16  
18 17 def self.searchkick_index
19 18 index = class_variable_get :@@searchkick_index
... ...
lib/searchkick/reindex.rb
... ... @@ -203,7 +203,7 @@ module Searchkick
203 203 }
204 204 }
205 205  
206   - if searchkick_env == "test"
  206 + if Searchkick.env == "test"
207 207 settings.merge!(number_of_shards: 1, number_of_replicas: 0)
208 208 end
209 209  
... ...