| 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 LoadError, 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: Ultrasphinx::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: # stable sort classes by name rather than rely on hash order
43: model_list = MODEL_CONFIGURATION.keys.sort
44: say "available models are #{model_list.to_sentence}"
45: File.open(CONF_PATH, "w") do |conf|
46: conf.puts global_header
47: say "generating SQL"
48:
49: INDEXES.each do |index|
50: sources = []
51: cached_groups = Fields.instance.groups.join("\n")
52:
53: model_list.each_with_index do |model, class_id|
54: options = MODEL_CONFIGURATION[model]
55: klass = model.constantize
56: source = "#{model.tableize.gsub('/', '__')}_#{index}"
57:
58: if index != DELTA_INDEX or options['delta']
59: # If we are building the delta, we only want to include the models that requested it
60: conf.puts build_source(index, Fields.instance, model, options, class_id, klass, source, cached_groups)
61: sources << source
62: end
63: end
64:
65: if sources.any?
66: # Don't generate a delta index if there are no delta tables
67: conf.puts build_index(index, sources)
68: end
69:
70: end
71: end
72: end