flying-sphinx 1.3.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +4 -6
  3. data/Appraisals +14 -10
  4. data/HISTORY +8 -0
  5. data/README.textile +4 -6
  6. data/flying-sphinx.gemspec +1 -2
  7. data/lib/flying_sphinx.rb +5 -15
  8. data/lib/flying_sphinx/cli.rb +17 -80
  9. data/lib/flying_sphinx/commands.rb +35 -0
  10. data/lib/flying_sphinx/commands/base.rb +86 -0
  11. data/lib/flying_sphinx/commands/clear.rb +7 -0
  12. data/lib/flying_sphinx/commands/configure.rb +7 -0
  13. data/lib/flying_sphinx/commands/index_sql.rb +33 -0
  14. data/lib/flying_sphinx/commands/merge.rb +17 -0
  15. data/lib/flying_sphinx/commands/prepare.rb +7 -0
  16. data/lib/flying_sphinx/commands/rebuild.rb +7 -0
  17. data/lib/flying_sphinx/commands/reset.rb +7 -0
  18. data/lib/flying_sphinx/commands/restart.rb +7 -0
  19. data/lib/flying_sphinx/commands/rotate.rb +7 -0
  20. data/lib/flying_sphinx/commands/running.rb +7 -0
  21. data/lib/flying_sphinx/commands/start.rb +7 -0
  22. data/lib/flying_sphinx/commands/start_attached.rb +10 -0
  23. data/lib/flying_sphinx/commands/stop.rb +7 -0
  24. data/lib/flying_sphinx/configuration_options.rb +11 -5
  25. data/lib/flying_sphinx/configurer.rb +7 -2
  26. data/lib/flying_sphinx/railtie.rb +7 -5
  27. data/lib/flying_sphinx/rake_interface.rb +25 -0
  28. data/lib/flying_sphinx/response/invalid.rb +1 -1
  29. data/lib/flying_sphinx/setting_files.rb +2 -2
  30. data/lib/flying_sphinx/tasks.rb +31 -24
  31. data/lib/flying_sphinx/tasks/deprecated.rb +31 -0
  32. data/lib/flying_sphinx/tasks/replaced.rb +27 -0
  33. data/lib/flying_sphinx/version.rb +1 -1
  34. data/spec/acceptance/configuring_spec.rb +7 -7
  35. data/spec/acceptance/start_or_stop_sphinx_spec.rb +7 -4
  36. data/spec/flying_sphinx/action_spec.rb +1 -1
  37. data/spec/flying_sphinx/commands/clear_spec.rb +22 -0
  38. data/spec/flying_sphinx/commands/configure_spec.rb +38 -0
  39. data/spec/flying_sphinx/commands/index_sql_spec.rb +69 -0
  40. data/spec/flying_sphinx/commands/merge_spec.rb +30 -0
  41. data/spec/flying_sphinx/commands/rebuild_spec.rb +26 -0
  42. data/spec/flying_sphinx/commands/reset_spec.rb +26 -0
  43. data/spec/flying_sphinx/commands/restart_spec.rb +23 -0
  44. data/spec/flying_sphinx/commands/rotate_spec.rb +22 -0
  45. data/spec/flying_sphinx/commands/running_spec.rb +24 -0
  46. data/spec/flying_sphinx/commands/start_attached_spec.rb +14 -0
  47. data/spec/flying_sphinx/commands/start_spec.rb +23 -0
  48. data/spec/flying_sphinx/commands/stop_spec.rb +23 -0
  49. data/spec/flying_sphinx/configurer_spec.rb +147 -0
  50. data/spec/support/command_helpers.rb +11 -0
  51. data/spec/support/multipart.rb +10 -6
  52. metadata +51 -27
  53. data/lib/flying_sphinx/binary.rb +0 -7
  54. data/lib/flying_sphinx/binary/translator.rb +0 -48
  55. data/lib/flying_sphinx/controller.rb +0 -104
  56. data/lib/flying_sphinx/rails.rb +0 -7
  57. data/lib/flying_sphinx/sphinxql.rb +0 -7
  58. data/lib/flying_sphinx/sphinxql/translator.rb +0 -26
  59. data/spec/flying_sphinx/controller_spec.rb +0 -71
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CommandHelpers
4
+ def configuration_double(stubs = {})
5
+ double("ThinkingSphinx::Configuration", {:settings => {}}.merge(stubs))
6
+ end
7
+ end
8
+
9
+ RSpec.configure do |config|
10
+ config.include CommandHelpers
11
+ end
@@ -6,20 +6,24 @@ end
6
6
 
7
7
  class MultipartRequestPattern < WebMock::RequestPattern
8
8
  def with_file(&block)
9
- with { |request| block.call MultipartRequestToFile.call(request) }
9
+ with { |request| block.call MultipartRequest.new(request).file }
10
10
  end
11
- end
12
11
 
13
- class MultipartRequestToFile
14
- def self.call(request)
15
- new(request).call
12
+ def with_params(&block)
13
+ with { |request| block.call MultipartRequest.new(request).params }
16
14
  end
15
+ end
17
16
 
17
+ class MultipartRequest
18
18
  def initialize(request)
19
19
  @request = request
20
20
  end
21
21
 
22
- def call
22
+ def params
23
+ parsed
24
+ end
25
+
26
+ def file
23
27
  parsed["file"][:tempfile].read
24
28
  end
25
29
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flying-sphinx
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-04 00:00:00.000000000 Z
11
+ date: 2018-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ey-hmac
@@ -80,34 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.3'
83
- - !ruby/object:Gem::Dependency
84
- name: riddle
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: 1.5.6
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: 1.5.6
97
83
  - !ruby/object:Gem::Dependency
98
84
  name: thinking-sphinx
99
85
  requirement: !ruby/object:Gem::Requirement
100
86
  requirements:
101
87
  - - ">="
102
88
  - !ruby/object:Gem::Version
103
- version: 1.5.0
89
+ version: 4.0.0
104
90
  type: :runtime
105
91
  prerelease: false
106
92
  version_requirements: !ruby/object:Gem::Requirement
107
93
  requirements:
108
94
  - - ">="
109
95
  - !ruby/object:Gem::Version
110
- version: 1.5.0
96
+ version: 4.0.0
111
97
  - !ruby/object:Gem::Dependency
112
98
  name: appraisal
113
99
  requirement: !ruby/object:Gem::Requirement
@@ -244,34 +230,59 @@ files:
244
230
  - lib/flying_sphinx.rb
245
231
  - lib/flying_sphinx/action.rb
246
232
  - lib/flying_sphinx/api.rb
247
- - lib/flying_sphinx/binary.rb
248
- - lib/flying_sphinx/binary/translator.rb
249
233
  - lib/flying_sphinx/cli.rb
234
+ - lib/flying_sphinx/commands.rb
235
+ - lib/flying_sphinx/commands/base.rb
236
+ - lib/flying_sphinx/commands/clear.rb
237
+ - lib/flying_sphinx/commands/configure.rb
238
+ - lib/flying_sphinx/commands/index_sql.rb
239
+ - lib/flying_sphinx/commands/merge.rb
240
+ - lib/flying_sphinx/commands/prepare.rb
241
+ - lib/flying_sphinx/commands/rebuild.rb
242
+ - lib/flying_sphinx/commands/reset.rb
243
+ - lib/flying_sphinx/commands/restart.rb
244
+ - lib/flying_sphinx/commands/rotate.rb
245
+ - lib/flying_sphinx/commands/running.rb
246
+ - lib/flying_sphinx/commands/start.rb
247
+ - lib/flying_sphinx/commands/start_attached.rb
248
+ - lib/flying_sphinx/commands/stop.rb
250
249
  - lib/flying_sphinx/configuration.rb
251
250
  - lib/flying_sphinx/configuration_options.rb
252
251
  - lib/flying_sphinx/configurer.rb
253
- - lib/flying_sphinx/controller.rb
254
- - lib/flying_sphinx/rails.rb
255
252
  - lib/flying_sphinx/railtie.rb
253
+ - lib/flying_sphinx/rake_interface.rb
256
254
  - lib/flying_sphinx/request/hmac.rb
257
255
  - lib/flying_sphinx/response/invalid.rb
258
256
  - lib/flying_sphinx/response/json.rb
259
257
  - lib/flying_sphinx/response/logger.rb
260
258
  - lib/flying_sphinx/setting_files.rb
261
259
  - lib/flying_sphinx/sinatra.rb
262
- - lib/flying_sphinx/sphinxql.rb
263
- - lib/flying_sphinx/sphinxql/translator.rb
264
260
  - lib/flying_sphinx/tasks.rb
261
+ - lib/flying_sphinx/tasks/deprecated.rb
262
+ - lib/flying_sphinx/tasks/replaced.rb
265
263
  - lib/flying_sphinx/version.rb
266
264
  - spec/acceptance/configuring_spec.rb
267
265
  - spec/acceptance/get_info_spec.rb
268
266
  - spec/acceptance/start_or_stop_sphinx_spec.rb
269
267
  - spec/flying_sphinx/action_spec.rb
270
268
  - spec/flying_sphinx/api_spec.rb
269
+ - spec/flying_sphinx/commands/clear_spec.rb
270
+ - spec/flying_sphinx/commands/configure_spec.rb
271
+ - spec/flying_sphinx/commands/index_sql_spec.rb
272
+ - spec/flying_sphinx/commands/merge_spec.rb
273
+ - spec/flying_sphinx/commands/rebuild_spec.rb
274
+ - spec/flying_sphinx/commands/reset_spec.rb
275
+ - spec/flying_sphinx/commands/restart_spec.rb
276
+ - spec/flying_sphinx/commands/rotate_spec.rb
277
+ - spec/flying_sphinx/commands/running_spec.rb
278
+ - spec/flying_sphinx/commands/start_attached_spec.rb
279
+ - spec/flying_sphinx/commands/start_spec.rb
280
+ - spec/flying_sphinx/commands/stop_spec.rb
271
281
  - spec/flying_sphinx/configuration_spec.rb
272
- - spec/flying_sphinx/controller_spec.rb
282
+ - spec/flying_sphinx/configurer_spec.rb
273
283
  - spec/flying_sphinx/setting_files_spec.rb
274
284
  - spec/spec_helper.rb
285
+ - spec/support/command_helpers.rb
275
286
  - spec/support/hmac.rb
276
287
  - spec/support/local_pusher.rb
277
288
  - spec/support/multipart.rb
@@ -295,7 +306,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
295
306
  version: '0'
296
307
  requirements: []
297
308
  rubyforge_project:
298
- rubygems_version: 2.5.2.1
309
+ rubygems_version: 2.7.6
299
310
  signing_key:
300
311
  specification_version: 4
301
312
  summary: Sphinx in the Cloud
@@ -305,10 +316,23 @@ test_files:
305
316
  - spec/acceptance/start_or_stop_sphinx_spec.rb
306
317
  - spec/flying_sphinx/action_spec.rb
307
318
  - spec/flying_sphinx/api_spec.rb
319
+ - spec/flying_sphinx/commands/clear_spec.rb
320
+ - spec/flying_sphinx/commands/configure_spec.rb
321
+ - spec/flying_sphinx/commands/index_sql_spec.rb
322
+ - spec/flying_sphinx/commands/merge_spec.rb
323
+ - spec/flying_sphinx/commands/rebuild_spec.rb
324
+ - spec/flying_sphinx/commands/reset_spec.rb
325
+ - spec/flying_sphinx/commands/restart_spec.rb
326
+ - spec/flying_sphinx/commands/rotate_spec.rb
327
+ - spec/flying_sphinx/commands/running_spec.rb
328
+ - spec/flying_sphinx/commands/start_attached_spec.rb
329
+ - spec/flying_sphinx/commands/start_spec.rb
330
+ - spec/flying_sphinx/commands/stop_spec.rb
308
331
  - spec/flying_sphinx/configuration_spec.rb
309
- - spec/flying_sphinx/controller_spec.rb
332
+ - spec/flying_sphinx/configurer_spec.rb
310
333
  - spec/flying_sphinx/setting_files_spec.rb
311
334
  - spec/spec_helper.rb
335
+ - spec/support/command_helpers.rb
312
336
  - spec/support/hmac.rb
313
337
  - spec/support/local_pusher.rb
314
338
  - spec/support/multipart.rb
@@ -1,7 +0,0 @@
1
- module FlyingSphinx::Binary
2
- def self.load
3
- require 'flying_sphinx/binary/translator'
4
-
5
- FlyingSphinx.translator = Translator.new FlyingSphinx::Configuration.new
6
- end
7
- end
@@ -1,48 +0,0 @@
1
- class FlyingSphinx::Binary::Translator
2
- def initialize(configuration)
3
- ThinkingSphinx.remote_sphinx = true
4
-
5
- thinking_sphinx.controller = FlyingSphinx::Controller.new configuration.api
6
- thinking_sphinx.address = configuration.host
7
- thinking_sphinx.port = configuration.port
8
- thinking_sphinx.configuration.searchd.client_key =
9
- configuration.client_key
10
-
11
- if ENV['DATABASE_URL'] && ENV['DATABASE_URL'][/^mysql/].nil?
12
- ThinkingSphinx.database_adapter = Class.new(ThinkingSphinx::PostgreSQLAdapter) do
13
- def setup
14
- create_array_accum_function
15
- end
16
- end
17
- end
18
- end
19
-
20
- def sphinx_configuration
21
- @sphinx_configuration ||= begin
22
- generate_configuration
23
- thinking_sphinx.configuration.searchd.client_key =
24
- FlyingSphinx::Configuration.new.client_key
25
- thinking_sphinx.configuration.render
26
- end
27
- end
28
-
29
- def sphinx_indices
30
- @sphinx_indices ||= begin
31
- generate_configuration
32
- thinking_sphinx.configuration.indices
33
- end
34
- end
35
-
36
- private
37
-
38
- def thinking_sphinx
39
- ThinkingSphinx::Configuration.instance
40
- end
41
-
42
- def generate_configuration
43
- return if @generated_configuration
44
-
45
- thinking_sphinx.generate
46
- @generated_configuration = true
47
- end
48
- end
@@ -1,104 +0,0 @@
1
- class FlyingSphinx::Controller
2
- DEFAULT_TIMEOUT = 60
3
- @index_timeout = 60 * 60 * 3 # 3 hours
4
-
5
- # For backwards compatibility. These aren't actually used here.
6
- attr_accessor :path, :bin_path, :searchd_binary_name, :indexer_binary_name
7
-
8
- def self.index_timeout
9
- @index_timeout
10
- end
11
-
12
- def self.index_timeout=(index_timeout)
13
- @index_timeout = index_timeout
14
- end
15
-
16
- def initialize(api)
17
- @api = api
18
- end
19
-
20
- def configure(file = nil)
21
- run_action_with_path 'configure', file
22
- end
23
-
24
- def index(*indices)
25
- options = indices.last.is_a?(Hash) ? indices.pop : {}
26
- async = indices.any? && !options[:verbose]
27
- options[:indices] = indices.join(',')
28
-
29
- if async
30
- send_action 'index', options.merge(:unique => 'true')
31
- else
32
- ::Delayed::Job.delete_all(
33
- "handler LIKE '--- !ruby/object:FlyingSphinx::%'"
34
- ) if defined?(::Delayed) && ::Delayed::Job.table_exists?
35
-
36
- run_action 'index', self.class.index_timeout, options
37
- end
38
-
39
- true
40
- end
41
-
42
- def rebuild
43
- run_action_with_path 'rebuild', nil, self.class.index_timeout
44
- end
45
-
46
- def regenerate(file = nil)
47
- reset file
48
-
49
- interface = ThinkingSphinx::RakeInterface.new
50
- if interface.respond_to?(:generate)
51
- interface.generate
52
- else
53
- interface.rt.index
54
- end
55
- end
56
-
57
- def reset(file = nil)
58
- run_action_with_path 'reset', file
59
- end
60
-
61
- def restart
62
- run_action 'restart'
63
- end
64
-
65
- def rotate
66
- run_action 'rotate'
67
- end
68
-
69
- def running?
70
- true
71
- end
72
-
73
- def sphinx_version
74
- '2.0.4'
75
- end
76
-
77
- def start(options = {})
78
- run_action 'start'
79
- end
80
-
81
- def stop
82
- run_action 'stop'
83
- end
84
-
85
- private
86
-
87
- attr_reader :api
88
-
89
- def run_action(action, timeout = DEFAULT_TIMEOUT, parameters = {})
90
- FlyingSphinx::Action.perform api.identifier, timeout do
91
- send_action action, parameters
92
- end
93
- end
94
-
95
- def run_action_with_path(action, file = nil, timeout = DEFAULT_TIMEOUT)
96
- path = FlyingSphinx::Configurer.new(api, file).call
97
-
98
- run_action action, timeout, :path => path
99
- end
100
-
101
- def send_action(action, parameters = {})
102
- api.post '/perform', parameters.merge(:action => action)
103
- end
104
- end
@@ -1,7 +0,0 @@
1
- require 'action_controller/dispatcher'
2
-
3
- if ENV['FLYING_SPHINX_IDENTIFIER'] || ENV['STAGED_SPHINX_IDENTIFIER']
4
- ActionController::Dispatcher.to_prepare :flying_sphinx do
5
- FlyingSphinx::Binary.load
6
- end
7
- end
@@ -1,7 +0,0 @@
1
- module FlyingSphinx::SphinxQL
2
- def self.load
3
- require 'flying_sphinx/sphinxql/translator'
4
-
5
- FlyingSphinx.translator = Translator.new FlyingSphinx::Configuration.new
6
- end
7
- end
@@ -1,26 +0,0 @@
1
- class FlyingSphinx::SphinxQL::Translator
2
- def initialize(configuration)
3
- thinking_sphinx.controller = FlyingSphinx::Controller.new configuration.api
4
-
5
- thinking_sphinx.settings['connection_options'] = {
6
- :host => configuration.host,
7
- :port => 9306,
8
- :username => configuration.username
9
- }
10
- end
11
-
12
- def sphinx_configuration
13
- @sphinx_configuration ||= thinking_sphinx.render
14
- end
15
-
16
- def sphinx_indices
17
- sphinx_configuration
18
- thinking_sphinx.indices
19
- end
20
-
21
- private
22
-
23
- def thinking_sphinx
24
- ThinkingSphinx::Configuration.instance
25
- end
26
- end
@@ -1,71 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe FlyingSphinx::Controller do
4
- let(:controller) { FlyingSphinx::Controller.new api }
5
- let(:api) { double 'API', :identifier => 'foo', :put => true,
6
- :get => {"path" => "/foo", "url" => "https://confserver", "status" => "OK"} }
7
- let(:action_class) { double }
8
- let(:configuration) { double 'TS Configuration' }
9
- let(:setting_files) { double :to_hash => {'extra' => 'wordforms/txt.txt',
10
- 'wordforms/txt.txt' => 'something'} }
11
- let(:translator) { double :sphinx_configuration => 'indexer ...' }
12
-
13
- before :each do
14
- stub_const 'FlyingSphinx::Action', action_class
15
- action_class.stub(:perform) do |identifier, &block|
16
- block.call
17
- end
18
-
19
- stub_const 'ThinkingSphinx::Configuration',
20
- double(:instance => configuration)
21
-
22
- stub_const 'FlyingSphinx::SettingFiles', double(:new => setting_files)
23
- FlyingSphinx.stub :translator => translator
24
-
25
- stub_request(:post, "https://confserver").to_return(:status => 200)
26
- end
27
-
28
- describe 'configure' do
29
- it 'sends data to the server' do
30
- api.should_receive(:post)
31
-
32
- controller.configure
33
- end
34
-
35
- it 'sends through gzipped configuration archive' do
36
- expect(api).to receive(:post).with '/perform',
37
- :action => 'configure',
38
- :path => '/foo'
39
-
40
- controller.configure
41
-
42
- expect(
43
- a_multipart_request(:post, 'https://confserver').
44
- with_file { |contents|
45
- reader = GZippedTar::Reader.new contents
46
-
47
- reader.read("sphinx/raw.conf") == "indexer ..." &&
48
- reader.read("sphinx/version.txt") == "2.2.3" &&
49
- reader.read("wordforms/txt.txt") == "something"
50
- }
51
- ).to have_been_made
52
- end
53
-
54
- it 'sends through file if provided' do
55
- expect(api).to receive(:post).with '/perform',
56
- :action => 'configure',
57
- :path => '/foo'
58
-
59
- controller.configure 'searchd ...'
60
-
61
- expect(
62
- a_multipart_request(:post, 'https://confserver').
63
- with_file { |contents|
64
- reader = GZippedTar::Reader.new contents
65
-
66
- reader.read("sphinx/raw.conf") == "searchd ..."
67
- }
68
- ).to have_been_made
69
- end
70
- end
71
- end