Class: Ultrasphinx::Configure
- Extended by:
- Associations
- Defined in:
- lib/ultrasphinx/configure.rb
Class Method Summary collapse
-
.load_constants ⇒ Object
Force all the indexed models to load and register in the MODEL_CONFIGURATION hash.
-
.run ⇒ Object
Main SQL builder.
Methods included from Associations
get_association, get_association_model
Class Method Details
.load_constants ⇒ Object
Force all the indexed models to load and register in the MODEL_CONFIGURATION hash.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ultrasphinx/configure.rb', line 9 def load_constants Dir.chdir "#{RAILS_ROOT}/app/models/" do Dir["**/*.rb"].each do |filename| open(filename) do |file| begin if file.grep(/is_indexed/).any? filename = filename[0..-4] begin File.basename(filename).camelize.constantize rescue NameError => e filename.camelize.constantize end end rescue Object => e say "warning: possibly critical autoload error on #{filename}" say e.inspect #say e.backtrace.join("\n") if RAILS_ENV == "development" end end end end # Build the field-to-type mappings. Fields.instance.configure(MODEL_CONFIGURATION) end |
.run ⇒ Object
Main SQL builder.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ultrasphinx/configure.rb', line 38 def run load_constants say "rebuilding configurations for #{RAILS_ENV} environment" say "available models are #{MODEL_CONFIGURATION.keys.to_sentence}" File.open(CONF_PATH, "w") do |conf| conf.puts global_header sources = [] say "generating SQL" cached_groups = Fields.instance.groups.join("\n") MODEL_CONFIGURATION.each_with_index do |, class_id| model, = klass, source = model.constantize, model.tableize.gsub('/', '__') sources << source conf.puts build_source(Fields.instance, model, , class_id, klass, source, cached_groups) end conf.puts build_index(sources) end end |