Sha256: a7490117094018b5c0cfec117eb26b2b4dd9bad3173538e8393fb0f5117aa332

Contents?: true

Size: 1012 Bytes

Versions: 2

Compression:

Stored size: 1012 Bytes

Contents

require 'thinking_sphinx'
require 'rails'

module ThinkingSphinx
  class Railtie < Rails::Railtie

    initializer "thinking_sphinx.active_record" do
      if defined?(ActiveRecord)
        ::ActiveRecord::Base.send(:include, ThinkingSphinx::ActiveRecord)
      end
    end

    initializer "thinking_sphinx.set_app_root" do |app|
      ThinkingSphinx::Configuration.instance.reset # Rails has setup app now
    end

    config.to_prepare do
      I18n.backend.reload!
      I18n.backend.available_locales
      
      # ActiveRecord::Base.to_crc32s is dependant on the subclasses being loaded
      # consistently. When the environment is reset, subclasses/descendants will
      # be lost but our context will not reload them for us.
      #
      # We reset the context which causes the subclasses/descendants to be
      # reloaded next time the context is called.
      # 
      ThinkingSphinx.reset_context!
    end

    rake_tasks do
      load File.expand_path('../tasks.rb', __FILE__)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
thinking-sphinx-2.0.0.rc2 lib/thinking_sphinx/railtie.rb
thinking-sphinx-2.0.0.rc1 lib/thinking_sphinx/railtie.rb