Class | Ultrasphinx::Configure |
In: |
lib/ultrasphinx/configure.rb
|
Parent: | Object |
Force all the indexed models to load and register in the MODEL_CONFIGURATION hash.
# File lib/ultrasphinx/configure.rb, line 9 9: def load_constants 10: 11: Dir.chdir "#{RAILS_ROOT}/app/models/" do 12: Dir["**/*.rb"].each do |filename| 13: open(filename) do |file| 14: begin 15: if file.grep(/^\s+is_indexed/).any? 16: filename = filename[0..-4] 17: begin 18: File.basename(filename).camelize.constantize 19: rescue NameError => e 20: filename.camelize.constantize 21: end 22: end 23: rescue Object => e 24: say "warning: critical autoload error on #{filename}; try referencing \"#{filename.camelize}\" directly in the console" 25: #say e.backtrace.join("\n") if RAILS_ENV == "development" 26: end 27: end 28: end 29: end 30: 31: # Build the field-to-type mappings. 32: Fields.instance.configure(MODEL_CONFIGURATION) 33: end
Main SQL builder.
# File lib/ultrasphinx/configure.rb, line 37 37: def run 38: 39: load_constants 40: 41: say "rebuilding configurations for #{RAILS_ENV} environment" 42: say "available models are #{MODEL_CONFIGURATION.keys.to_sentence}" 43: File.open(CONF_PATH, "w") do |conf| 44: conf.puts global_header 45: say "generating SQL" 46: 47: INDEXES.each do |index| 48: sources = [] 49: cached_groups = Fields.instance.groups.join("\n") 50: 51: MODEL_CONFIGURATION.each_with_index do |model_and_options, class_id| 52: # This relies on hash sort order being deterministic per-machine 53: model, options = model_and_options 54: klass = model.constantize 55: source = "#{model.tableize.gsub('/', '__')}_#{index}" 56: 57: if index != DELTA_INDEX or options['delta'] 58: # If we are building the delta, we only want to include the models that requested it 59: conf.puts build_source(index, Fields.instance, model, options, class_id, klass, source, cached_groups) 60: sources << source 61: end 62: end 63: 64: if sources.any? 65: # Don't generate a delta index if there are no delta tables 66: conf.puts build_index(index, sources) 67: end 68: 69: end 70: end 71: end