Class: Sunspot::SessionProxy::MulticoreSessionProxy

Inherits:
AbstractSessionProxy show all
Defined in:
lib/sunspot/session_proxy/multicore_session_proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractSessionProxy

delegate, not_supported

Constructor Details

#initialize(cores) ⇒ MulticoreSessionProxy

Returns a new instance of MulticoreSessionProxy.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/sunspot/session_proxy/multicore_session_proxy.rb', line 5

def initialize( cores )
  @sessions = {}
  @cores ||= []
  ( @cores << cores ).flatten!
  cores.each do |core|

    # can't find a better way grab the sunspot.yml configuration (:user_configuration is a private method)
    modified_config = Marshal.load( Marshal.dump( Sunspot::Rails.configuration.send(:user_configuration) ) )

    modified_config["solr"]["path"] = File.join(
      ( modified_config["solr"]["path"] || Sunspot::Rails.configuration.path ), core )
      
    extended_config = Sunspot::Rails::ExtendedConfiguration.new(modified_config)
    session = @sessions[core] = Sunspot::Rails.build_session(extended_config)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sunspot/session_proxy/multicore_session_proxy.rb', line 24

def method_missing(method, *args, &block)
  inspectable_args = args.flatten
  types = inspectable_args.select(&:searchable?) rescue []
  types += inspectable_args.select{|a| a.class.searchable? rescue false }
  
  self.selected_session = session_for_types(types) || self.selected_session
  
  if self.selected_session.respond_to?(method)
    begin
      self.selected_session.send(method, *args, &block) 
    rescue Exception => e
      (puts "method #{method} caused: #{e.message}")
    end
  else
    # raise NoMethodError, "Method #{method} isn't defined on session"
    # logger.info("do nothing")
    # super
    # self.selected_session.send(method, *args, &block)
    return false
  end
end

Instance Attribute Details

#selected_sessionObject

Returns the value of attribute selected_session.



22
23
24
# File 'lib/sunspot/session_proxy/multicore_session_proxy.rb', line 22

def selected_session
  @selected_session
end