forked from sunspot/sunspot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_proxy.rb
71 lines (70 loc) · 2.32 KB
/
session_proxy.rb
1
2
3
4
5
6
7
8
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
module Sunspot
#
# This module contains several Session Proxy implementations, which can be
# used to decorate one or more Session objects and add extra functionality.
# The user can also implement their own Session Proxy classes; a Session Proxy
# must simply implement the same public API as the Sunspot::Session class.
#
# When implementing a session proxy, some methods of Session may not be
# practical, or even logical, to implement. In this case, the method should
# raise a Sunspot::SessionProxy::NotSupportedError (several methods in the
# built-in session proxies raise this error).
#
# To use a session proxy in normal Sunspot usage, you can use the
# Sunspot.session= method, which will cause Sunspot to delegate all of its
# session-related class methods (most of them) to the proxy. Session proxies
# can also easily be chained, although the details of chaining depend on the
# proxy implementation.
#
# ===== Example: Chain a MasterSlaveSessionProxy with a ThreadLocalSessionProxy
#
# master_session = Sunspot::SessionProxy::ThreadLocalSessionProxy.new
# slave_session = Sunspot::SessionProxy::ThreadLocalSessionProxy.new
# master_session.config.solr.url = 'http://master-solr.local:9080/solr'
# slave_session.config.solr.url = 'http://slave-solr.local:9080/solr'
# Sunspot.session = Sunspot::SessionProxy::MasterSlaveSessionProxy.new(master_session, slave_session)
#
module SessionProxy
NotSupportedError = Class.new(Exception)
autoload(
:ThreadLocalSessionProxy,
File.join(
File.dirname(__FILE__),
'session_proxy',
'thread_local_session_proxy'
)
)
autoload(
:MasterSlaveSessionProxy,
File.join(
File.dirname(__FILE__),
'session_proxy',
'master_slave_session_proxy'
)
)
autoload(
:ShardingSessionProxy,
File.join(
File.dirname(__FILE__),
'session_proxy',
'sharding_session_proxy'
)
)
autoload(
:ClassShardingSessionProxy,
File.join(
File.dirname(__FILE__),
'session_proxy',
'class_sharding_session_proxy'
)
)
autoload(
:IdShardingSessionProxy,
File.join(
File.dirname(__FILE__),
'session_proxy',
'id_sharding_session_proxy'
)
)
end
end