Sha256: 8bba27f287687f6afdf198b73dfa4a05c61d774fb0c9bc79cb41ac9af28179ee

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require 'sunspot'
require 'sunspot-rails-failover/master_slave_with_failover_session_proxy'
require 'sunspot-rails-failover/exception_handler_adapter'

module Sunspot
  module Rails
    module Failover
      class << self
        attr_accessor :exception_handler
        
        def setup
          Sunspot.session = if Sunspot::Rails.configuration.has_master?
            Sunspot::SessionProxy::MasterSlaveWithFailoverSessionProxy.new(
              Sunspot::Session.new(master_config), Sunspot::Session.new(slave_config)
            )
          else
            Sunspot::SessionProxy::ThreadLocalSessionProxy.new(slave_config)
          end
        end
        
      private
      
        def slave_config
          build_config('solr', 'url')
        end
        
        def master_config
          build_config('master_solr', 'url')
        end
        
        def build_config(*keys)
          Sunspot::Configuration.build.tap do |config|
            config.solr.url = Sunspot::Rails.configuration.send :user_configuration_from_key, *keys
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sunspot-rails-failover-0.0.3 lib/sunspot-rails-failover.rb