diff --git a/lib/riddle/configuration/common.rb b/lib/riddle/configuration/common.rb index 7890f49..dc2ef1d 100644 --- a/lib/riddle/configuration/common.rb +++ b/lib/riddle/configuration/common.rb @@ -9,9 +9,10 @@ def self.settings ] end - attr_accessor *self.settings + attr_accessor :common_sphinx_configuration, *settings def render + return unless common_sphinx_configuration raise ConfigurationError unless valid? ( diff --git a/lib/riddle/configuration/indexer.rb b/lib/riddle/configuration/indexer.rb index 892e45e..8ae42ff 100644 --- a/lib/riddle/configuration/indexer.rb +++ b/lib/riddle/configuration/indexer.rb @@ -6,10 +6,18 @@ def self.settings :mem_limit, :max_iops, :max_iosize, :max_xmlpipe2_field, :write_buffer, :max_file_field_buffer, :on_file_field_error, :lemmatizer_cache + ] + shared_settings + end + + def self.shared_settings + [ + :json_autoconv_numbers, :json_autoconv_keynames, + :on_json_attr_error, :rlp_root, :rlp_environment, + :rlp_max_batch_size, :rlp_max_batch_docs ] end - attr_accessor *self.settings + attr_accessor :common_sphinx_configuration, *settings def render raise ConfigurationError unless valid? @@ -20,6 +28,15 @@ def render ["}", ""] ).join("\n") end + + + private + + def settings + settings = self.class.settings + settings -= self.class.shared_settings if common_sphinx_configuration + settings + end end end end diff --git a/lib/riddle/configuration/section.rb b/lib/riddle/configuration/section.rb index 2c965b5..805132e 100644 --- a/lib/riddle/configuration/section.rb +++ b/lib/riddle/configuration/section.rb @@ -12,7 +12,7 @@ def valid? private def settings_body - self.class.settings.select { |setting| + settings.select { |setting| !send(setting).nil? }.collect { |setting| if send(setting) == "" @@ -50,6 +50,10 @@ def rendered_setting(setting) output end + + def settings + self.class.settings + end end end end diff --git a/spec/unit/configuration/common_spec.rb b/spec/unit/configuration/common_spec.rb index a752097..d1c5391 100644 --- a/spec/unit/configuration/common_spec.rb +++ b/spec/unit/configuration/common_spec.rb @@ -17,21 +17,43 @@ common.should respond_to("#{setting}=".to_sym) end end - + it "should render a correct configuration" do common = Riddle::Configuration::Common.new - + common.common_sphinx_configuration = true + common.render.should == <<-COMMON common { } COMMON - + common.lemmatizer_base = "/tmp" common.render.should == <<-COMMON common { lemmatizer_base = /tmp +} + COMMON + end + + it "should not be present when common_sphinx_configuration is not set" do + common = Riddle::Configuration::Common.new + common.render.should be_nil + end + + it "should not be present when common_sphinx_configuration is false" do + common = Riddle::Configuration::Common.new + common.common_sphinx_configuration = false + common.render.should be_nil + end + + it "should render when common_sphinx_configuration is true" do + common = Riddle::Configuration::Common.new + common.common_sphinx_configuration = true + common.render.should == <<-COMMON +common +{ } COMMON end diff --git a/spec/unit/configuration/indexer_spec.rb b/spec/unit/configuration/indexer_spec.rb index 636a2ed..ee826f5 100644 --- a/spec/unit/configuration/indexer_spec.rb +++ b/spec/unit/configuration/indexer_spec.rb @@ -33,4 +33,41 @@ } INDEXER end + + it "should render shared settings when common_sphinx_configuration is not set" do + indexer = Riddle::Configuration::Indexer.new + indexer.rlp_root = '/tmp' + + indexer.render.should == <<-INDEXER +indexer +{ + rlp_root = /tmp +} + INDEXER + end + + it "should render shared settings when common_sphinx_configuration is false" do + indexer = Riddle::Configuration::Indexer.new + indexer.common_sphinx_configuration = false + indexer.rlp_root = '/tmp' + + indexer.render.should == <<-INDEXER +indexer +{ + rlp_root = /tmp +} + INDEXER + end + + it "should not render shared settings when common_sphinx_configuration is true" do + indexer = Riddle::Configuration::Indexer.new + indexer.common_sphinx_configuration = true + indexer.rlp_root = '/tmp' + + indexer.render.should == <<-INDEXER +indexer +{ +} + INDEXER + end end \ No newline at end of file