lib/thinking_sphinx/configuration.rb in hawkerb-thinking-sphinx-1.3.15 vs lib/thinking_sphinx/configuration.rb in hawkerb-thinking-sphinx-1.3.16

- old
+ new

@@ -65,11 +65,11 @@ CustomOptions = %w( disable_range ) attr_accessor :searchd_file_path, :allow_star, :database_yml_file, :app_root, :model_directories, :delayed_job_priority - attr_accessor :source_options, :index_options + attr_accessor :source_options, :index_options, :section_options attr_reader :environment, :configuration, :controller # Load in the configuration settings - this will look for config/sphinx.yml # and parse it according to the current environment. @@ -108,10 +108,11 @@ self.model_directories = ["#{app_root}/app/models/"] + Dir.glob("#{app_root}/vendor/plugins/*/app/models/") self.delayed_job_priority = 0 self.source_options = {} + self.section_options = {} self.index_options = { :charset_type => "utf-8" } parse_config @@ -139,11 +140,11 @@ @configuration.indexes.clear ThinkingSphinx.context.indexed_models.each do |model| model = model.constantize model.define_indexes - @configuration.indexes.concat model.to_riddle + @configuration.indexes.concat merge_with_section_options!(model.to_riddle) end open(file_path, "w") do |file| file.write @configuration.render end @@ -252,16 +253,20 @@ conf = YAML::load(ERB.new(IO.read(path)).result)[environment] conf.each do |key,value| self.send("#{key}=", value) if self.respond_to?("#{key}=") - - set_sphinx_setting self.source_options, key, value, SourceOptions - set_sphinx_setting self.index_options, key, value, IndexOptions - set_sphinx_setting self.index_options, key, value, CustomOptions - set_sphinx_setting @configuration.searchd, key, value - set_sphinx_setting @configuration.indexer, key, value + + if value.is_a?(Hash) + self.section_options[key] = value + else + set_sphinx_setting self.source_options, key, value, SourceOptions + set_sphinx_setting self.index_options, key, value, IndexOptions + set_sphinx_setting self.index_options, key, value, CustomOptions + set_sphinx_setting @configuration.searchd, key, value + set_sphinx_setting @configuration.indexer, key, value + end end unless conf.nil? self.bin_path += '/' unless self.bin_path.blank? if self.allow_star @@ -275,8 +280,21 @@ object[key.to_sym] = value if allowed.include?(key.to_s) else object.send("#{key}=", value) if object.respond_to?("#{key}") send("#{key}=", value) if self.respond_to?("#{key}") end + end + + def merge_with_section_options!(indexes) + indexes.each do |index| + if nested_values = section_options[index.name] + nested_values.each_pair {|key, val| index.send(:"#{key}=",val) } + end + + if index.respond_to?(:sources) + merge_with_section_options!(index.sources) + end + end + indexes end end end