class Riddle::Configuration::Parser
Constants
- INDEX_CLASSES
- SOURCE_CLASSES
Public Class Methods
new(input)
click to toggle source
# File lib/riddle/configuration/parser.rb, line 24 def initialize(input) @input = input end
Public Instance Methods
parse!()
click to toggle source
# File lib/riddle/configuration/parser.rb, line 28 def parse! set_common set_indexer set_searchd set_sources set_indices add_orphan_sources configuration end
Private Instance Methods
add_orphan_sources()
click to toggle source
# File lib/riddle/configuration/parser.rb, line 42 def add_orphan_sources all_names = sources.keys attached_names = configuration.indices.collect { |index| index.respond_to?(:sources) ? index.sources.collect(&:name) : [] }.flatten (all_names - attached_names).each do |name| configuration.sources << sources[name] end end
configuration()
click to toggle source
# File lib/riddle/configuration/parser.rb, line 57 def configuration @configuration ||= Riddle::Configuration.new end
each_with_prefix(prefix) { |gsub(/^#{prefix}\s+/, '').gsub(/\s*\{$/, ''), inner| ... }
click to toggle source
# File lib/riddle/configuration/parser.rb, line 65 def each_with_prefix(prefix) inner.keys.select { |key| key[/^#{prefix}\s+/] }.each do |key| yield key.gsub(/^#{prefix}\s+/, '').gsub(/\s*\{$/, ''), inner[key] end end
inner()
click to toggle source
# File lib/riddle/configuration/parser.rb, line 53 def inner @inner ||= InnerParser.new(@input).parse! end
set_common()
click to toggle source
# File lib/riddle/configuration/parser.rb, line 71 def set_common if inner['common'] && inner['common'].values.compact.any? configuration.common.common_sphinx_configuration = true end set_settings configuration.common, inner['common'] || {} end
set_indexer()
click to toggle source
# File lib/riddle/configuration/parser.rb, line 79 def set_indexer set_settings configuration.indexer, inner['indexer'] || {} end
set_indices()
click to toggle source
# File lib/riddle/configuration/parser.rb, line 104 def set_indices each_with_prefix 'index' do |name, settings| names = name.split(/\s*:\s*/) type = (settings.delete('type') || ['plain']).first index = INDEX_CLASSES[type].new names.first index.parent = names.last if names.length > 1 (settings.delete('source') || []).each do |source_name| index.sources << sources[source_name] end set_settings index, settings configuration.indices << index end end
set_searchd()
click to toggle source
# File lib/riddle/configuration/parser.rb, line 83 def set_searchd set_settings configuration.searchd, inner['searchd'] || {} end
set_setting(object, key, value)
click to toggle source
# File lib/riddle/configuration/parser.rb, line 129 def set_setting(object, key, value) if object.send(key).is_a?(Array) object.send(key) << value else object.send "#{key}=", value end end
set_settings(object, hash)
click to toggle source
# File lib/riddle/configuration/parser.rb, line 121 def set_settings(object, hash) hash.each do |key, values| values.each do |value| set_setting object, key, value end end end
set_sources()
click to toggle source
# File lib/riddle/configuration/parser.rb, line 87 def set_sources each_with_prefix 'source' do |name, settings| names = name.split(/\s*:\s*/) types = settings.delete('type') parent = names.length > 1 ? names.last : nil types ||= [sources[parent].type] if parent type = types.first source = SOURCE_CLASSES[type].new names.first, type source.parent = parent set_settings source, settings sources[source.name] = source end end
sources()
click to toggle source
# File lib/riddle/configuration/parser.rb, line 61 def sources @sources ||= {} end