Skip to content

Commit

Permalink
Merge pull request #83 from trevorsmith/common-setting
Browse files Browse the repository at this point in the history
Add a common_sphinx_configuration setting.
  • Loading branch information
pat committed Feb 28, 2014
2 parents 995d4df + 520ff5e commit bd0e1b3
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/riddle/configuration/common.rb
Expand Up @@ -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?

(
Expand Down
19 changes: 18 additions & 1 deletion lib/riddle/configuration/indexer.rb
Expand Up @@ -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?
Expand All @@ -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
6 changes: 5 additions & 1 deletion lib/riddle/configuration/section.rb
Expand Up @@ -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) == ""
Expand Down Expand Up @@ -50,6 +50,10 @@ def rendered_setting(setting)

output
end

def settings
self.class.settings
end
end
end
end
28 changes: 25 additions & 3 deletions spec/unit/configuration/common_spec.rb
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions spec/unit/configuration/indexer_spec.rb
Expand Up @@ -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

0 comments on commit bd0e1b3

Please sign in to comment.