flying-sphinx 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.5
1
+ 0.0.6
@@ -4,19 +4,51 @@ class FlyingSphinx::IndexRequest
4
4
  def initialize(configuration)
5
5
  @configuration = configuration
6
6
 
7
+ update_sphinx_configuration
8
+
7
9
  FlyingSphinx::Tunnel.connect(configuration) do
8
- begin_request
10
+ begin_request unless request_begun?
9
11
 
10
- while !request_complete?
11
- sleep(0.25)
12
- end
12
+ !request_complete?
13
13
  end
14
14
  end
15
15
 
16
16
  private
17
17
 
18
+ def update_sphinx_configuration
19
+ api.put '/app/update', :configuration => sphinx_configuration
20
+ end
21
+
22
+ def sphinx_configuration
23
+ ts_config = ThinkingSphinx::Configuration.instance
24
+ ts_config.port = configuration.port
25
+ ts_config.address = configuration.host
26
+
27
+ riddle_config = ts_config.configuration
28
+
29
+ ThinkingSphinx.context.indexed_models.each do |model|
30
+ model = model.constantize
31
+ model.define_indexes
32
+ riddle_config.indexes.concat model.to_riddle
33
+ end
34
+
35
+ riddle_config.indexes.each do |index|
36
+ index.sources.each do |source|
37
+ source.sql_host = '127.0.0.1'
38
+ source.sql_port = configuration.database_port
39
+ end
40
+ end
41
+
42
+ riddle_config.render
43
+ end
44
+
18
45
  def begin_request
19
- @index_id = api.post('/app/indices')
46
+ @index_id = api.post('/app/indices')
47
+ @request_begun = true
48
+ end
49
+
50
+ def request_begun?
51
+ @request_begun
20
52
  end
21
53
 
22
54
  def request_complete?
@@ -1,32 +1,25 @@
1
1
  class FlyingSphinx::Tunnel
2
- def self.connect(configuration)
2
+ def self.connect(configuration, &block)
3
3
  tunnel = new configuration
4
- tunnel.open
5
- tunnel.forward
6
-
7
- yield
8
-
9
- tunnel.close
4
+ tunnel.open do |session|
5
+ session.loop &block
6
+ end
10
7
  end
11
8
 
12
9
  def initialize(configuration)
13
10
  @configuration = configuration
14
11
  end
15
12
 
16
- def open
17
- @session = Net::SSH.start(@configuration.host, 'sphinx', ssh_options)
18
- end
19
-
20
- def forward
21
- @session.forward.remote(
22
- db_port, db_host, @configuration.database_port, '0.0.0.0'
23
- )
13
+ def open(&block)
14
+ Net::SSH.start(@configuration.host, 'sphinx', ssh_options) do |session|
15
+ session.forward.remote(
16
+ db_port, db_host, @configuration.database_port, '0.0.0.0'
17
+ )
18
+
19
+ yield session
20
+ end
24
21
  end
25
-
26
- def close
27
- @session.close
28
- end
29
-
22
+
30
23
  private
31
24
 
32
25
  def db_host
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flying-sphinx
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pat Allan