From f4655c29447eb0ce1bb3f8f438061a30ffc95daa Mon Sep 17 00:00:00 2001 From: "Robert L. Carpenter" Date: Mon, 8 Aug 2016 13:44:42 -0600 Subject: [PATCH 1/2] Allow app/chewy location to be changed via yml config --- lib/chewy/config.rb | 7 ++++++- lib/chewy/railtie.rb | 4 ++-- lib/chewy/rake_helper.rb | 2 +- spec/chewy/config_spec.rb | 1 + 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/chewy/config.rb b/lib/chewy/config.rb index 3792b5ad3..e540c67b1 100644 --- a/lib/chewy/config.rb +++ b/lib/chewy/config.rb @@ -36,7 +36,11 @@ class Config # in tests with transactional fixtures or transactional # DatabaseCleaner strategy. # - :use_after_commit_callbacks + :use_after_commit_callbacks, + + # Where Chewy expects to find index definitions + # within a Rails app folder. + :index_definition_path def self.delegated public_instance_methods - self.superclass.public_instance_methods - Singleton.public_instance_methods @@ -49,6 +53,7 @@ def initialize @root_strategy = :base @request_strategy = :atomic @use_after_commit_callbacks = true + @index_definition_path = 'app/chewy' end def transport_logger= logger diff --git a/lib/chewy/railtie.rb b/lib/chewy/railtie.rb index 6845c707f..e93ddd16f 100644 --- a/lib/chewy/railtie.rb +++ b/lib/chewy/railtie.rb @@ -70,9 +70,9 @@ def migrate(*args) app.config.middleware.insert_after(Rails::Rack::Logger, RequestStrategy) end - initializer 'chewy.add_app_chewy_path' do |app| + initializer 'chewy.add_index_definition_path' do |app| Chewy::Railtie.all_engines.each do |engine| - engine.paths.add 'app/chewy' + engine.paths.add Chewy.configuration[:index_definition_path] end end end diff --git a/lib/chewy/rake_helper.rb b/lib/chewy/rake_helper.rb index 43e9a57b1..e51b1cdd2 100644 --- a/lib/chewy/rake_helper.rb +++ b/lib/chewy/rake_helper.rb @@ -20,7 +20,7 @@ def subscribed_task_stats(&block) end def eager_load_chewy! - dirs = Chewy::Railtie.all_engines.map { |engine| engine.paths['app/chewy'] }.compact.map(&:existent).flatten.uniq + dirs = Chewy::Railtie.all_engines.map { |engine| engine.paths[ Chewy.configuration[:index_definition_path] ] }.compact.map(&:existent).flatten.uniq dirs.each do |dir| Dir.glob(File.join(dir, '**/*.rb')).each do |file| diff --git a/spec/chewy/config_spec.rb b/spec/chewy/config_spec.rb index 16400631b..21da658f8 100644 --- a/spec/chewy/config_spec.rb +++ b/spec/chewy/config_spec.rb @@ -12,6 +12,7 @@ its(:root_strategy) { should == :base } its(:request_strategy) { should == :atomic } its(:use_after_commit_callbacks) { should == true } + its(:index_definition_path) { should == 'app/chewy' } describe '#transport_logger=' do let(:logger) { Logger.new('/dev/null') } From 0b4775fff4c7581229a16ad6fa1f936e76ef1f70 Mon Sep 17 00:00:00 2001 From: "Robert L. Carpenter" Date: Wed, 10 Aug 2016 15:57:53 -0600 Subject: [PATCH 2/2] index_definition_path -> indices_path --- lib/chewy/config.rb | 4 ++-- lib/chewy/railtie.rb | 4 ++-- lib/chewy/rake_helper.rb | 2 +- spec/chewy/config_spec.rb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/chewy/config.rb b/lib/chewy/config.rb index e540c67b1..2ea73bfeb 100644 --- a/lib/chewy/config.rb +++ b/lib/chewy/config.rb @@ -40,7 +40,7 @@ class Config # Where Chewy expects to find index definitions # within a Rails app folder. - :index_definition_path + :indices_path def self.delegated public_instance_methods - self.superclass.public_instance_methods - Singleton.public_instance_methods @@ -53,7 +53,7 @@ def initialize @root_strategy = :base @request_strategy = :atomic @use_after_commit_callbacks = true - @index_definition_path = 'app/chewy' + @indices_path = 'app/chewy' end def transport_logger= logger diff --git a/lib/chewy/railtie.rb b/lib/chewy/railtie.rb index e93ddd16f..8ad5c6a71 100644 --- a/lib/chewy/railtie.rb +++ b/lib/chewy/railtie.rb @@ -70,9 +70,9 @@ def migrate(*args) app.config.middleware.insert_after(Rails::Rack::Logger, RequestStrategy) end - initializer 'chewy.add_index_definition_path' do |app| + initializer 'chewy.add_indices_path' do |app| Chewy::Railtie.all_engines.each do |engine| - engine.paths.add Chewy.configuration[:index_definition_path] + engine.paths.add Chewy.configuration[:indices_path] end end end diff --git a/lib/chewy/rake_helper.rb b/lib/chewy/rake_helper.rb index e51b1cdd2..a54b4e744 100644 --- a/lib/chewy/rake_helper.rb +++ b/lib/chewy/rake_helper.rb @@ -20,7 +20,7 @@ def subscribed_task_stats(&block) end def eager_load_chewy! - dirs = Chewy::Railtie.all_engines.map { |engine| engine.paths[ Chewy.configuration[:index_definition_path] ] }.compact.map(&:existent).flatten.uniq + dirs = Chewy::Railtie.all_engines.map { |engine| engine.paths[ Chewy.configuration[:indices_path] ] }.compact.map(&:existent).flatten.uniq dirs.each do |dir| Dir.glob(File.join(dir, '**/*.rb')).each do |file| diff --git a/spec/chewy/config_spec.rb b/spec/chewy/config_spec.rb index 21da658f8..8d8b9b5c4 100644 --- a/spec/chewy/config_spec.rb +++ b/spec/chewy/config_spec.rb @@ -12,7 +12,7 @@ its(:root_strategy) { should == :base } its(:request_strategy) { should == :atomic } its(:use_after_commit_callbacks) { should == true } - its(:index_definition_path) { should == 'app/chewy' } + its(:indices_path) { should == 'app/chewy' } describe '#transport_logger=' do let(:logger) { Logger.new('/dev/null') }