lostboy-workling_delta_indexer 0.1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.rdoc +26 -0
- data/VERSION.yml +4 -0
- data/lib/workling_delta/indexer.rb +11 -0
- data/lib/workling_delta/worker.rb +10 -0
- data/lib/workling_delta_indexer.rb +7 -0
- data/test/test_helper.rb +22 -0
- data/test/workling_delta/indexer_test.rb +20 -0
- data/test/workling_delta/worker_test.rb +46 -0
- metadata +74 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Dan Pickett
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= workling_delta_indexer
|
2
|
+
|
3
|
+
Use workling to manage your delta indexing with Pat Allan's Thinking Sphinx
|
4
|
+
|
5
|
+
== How to Use
|
6
|
+
|
7
|
+
Install the gem
|
8
|
+
|
9
|
+
gem install dpickett-workling_delta_indexer
|
10
|
+
|
11
|
+
Add the gem to your list of required gems in config/environment.rb
|
12
|
+
|
13
|
+
config.gem "dpickett-workling_delta_indexer",
|
14
|
+
:lib => "workling_delta_indexer"
|
15
|
+
|
16
|
+
Use WorklingDelta::Indexer as your Delta handler
|
17
|
+
|
18
|
+
define_index do
|
19
|
+
<index details>
|
20
|
+
|
21
|
+
set_property :delta => WorklingDelta::Indexer
|
22
|
+
end
|
23
|
+
|
24
|
+
== Copyright
|
25
|
+
|
26
|
+
Copyright (c) 2009 Dan Pickett. See LICENSE for details.
|
data/VERSION.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module WorklingDelta
|
2
|
+
class Indexer < ThinkingSphinx::Deltas::DefaultDelta
|
3
|
+
def index(model, instance = nil)
|
4
|
+
doc_id = instance ? instance.sphinx_document_id : nil
|
5
|
+
WorklingDelta::Worker.async_index(:delta_index_name => delta_index_name(model),
|
6
|
+
:document_id => doc_id, :core_index_name => core_index_name(model))
|
7
|
+
|
8
|
+
true
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class WorklingDelta::Worker < Workling::Base
|
2
|
+
def index(options = {})
|
3
|
+
ThinkingSphinx::Deltas::DeltaJob.new(options[:delta_index_name]).perform
|
4
|
+
|
5
|
+
if options[:document_id]
|
6
|
+
ThinkingSphinx::Deltas::FlagAsDeletedJob.new(options[:core_index_name],
|
7
|
+
options[:document_id]).perform
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
require 'shoulda'
|
5
|
+
require 'rr'
|
6
|
+
require 'active_support'
|
7
|
+
require 'active_support/core_ext'
|
8
|
+
|
9
|
+
RAILS_ENV = "test"
|
10
|
+
RAILS_DEFAULT_LOGGER = "/dev/null"
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'vendor'))
|
15
|
+
|
16
|
+
require "workling/lib/workling/discovery"
|
17
|
+
require "workling/lib/workling/base"
|
18
|
+
require 'workling_delta_indexer'
|
19
|
+
|
20
|
+
class Test::Unit::TestCase
|
21
|
+
include RR::Adapters::TestUnit
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
|
3
|
+
class WorklingDelta::IndexerTest < Test::Unit::TestCase
|
4
|
+
context "an indexer" do
|
5
|
+
should "spawn a worker with the delta index name when an index is triggered" do
|
6
|
+
mock(WorklingDelta::Worker).async_index(:index_name => "test_model_delta", :document_id => nil)
|
7
|
+
|
8
|
+
WorklingDelta::Indexer.new(ThinkingSphinx::Index.new(TestModel), {}).do_index(TestModel)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
class TestModel < ActiveRecord::Base
|
15
|
+
define_index do
|
16
|
+
indexes :id
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "test_helper")
|
2
|
+
|
3
|
+
class WorklingDelta::WorkerTest < Test::Unit::TestCase
|
4
|
+
context "a worker" do
|
5
|
+
setup do
|
6
|
+
@index_name = "the_delta_index"
|
7
|
+
@document_id = 1
|
8
|
+
|
9
|
+
@job = mock(Object)
|
10
|
+
mock(ThinkingSphinx::Deltas::DeltaJob).new(@index_name) { @job }
|
11
|
+
@job.perform
|
12
|
+
end
|
13
|
+
|
14
|
+
context "that doesn't receive a document id" do
|
15
|
+
|
16
|
+
should "perform a TS delta job with the index name" do
|
17
|
+
invoke_worker(:index_name => @index_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
should "not perform a flag as deleted job if I don't pass a document id" do
|
21
|
+
dont_allow(ThinkingSphinx::Deltas::FlagAsDeletedJob).new(
|
22
|
+
anything, anything)
|
23
|
+
|
24
|
+
invoke_worker(:index_name => @index_name)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
context "that receives a document id" do
|
30
|
+
should "trigger a flag as deleted job if I pass a document id" do
|
31
|
+
delete_job = mock(Object)
|
32
|
+
mock(ThinkingSphinx::Deltas::FlagAsDeletedJob).new(
|
33
|
+
@index_name, @document_id) { delete_job }
|
34
|
+
delete_job.perform
|
35
|
+
|
36
|
+
invoke_worker(:index_name => @index_name, :document_id => @document_id)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
def invoke_worker(options = {})
|
44
|
+
WorklingDelta::Worker.new.index(options)
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lostboy-workling_delta_indexer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Pickett
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-07 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: lostboy-thinking-sphinx
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.1.5
|
24
|
+
version:
|
25
|
+
description:
|
26
|
+
email: dpickett@enlightsolutions.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README.rdoc
|
33
|
+
- LICENSE
|
34
|
+
files:
|
35
|
+
- README.rdoc
|
36
|
+
- VERSION.yml
|
37
|
+
- lib/workling_delta
|
38
|
+
- lib/workling_delta/indexer.rb
|
39
|
+
- lib/workling_delta/worker.rb
|
40
|
+
- lib/workling_delta_indexer.rb
|
41
|
+
- test/test_helper.rb
|
42
|
+
- test/workling_delta
|
43
|
+
- test/workling_delta/indexer_test.rb
|
44
|
+
- test/workling_delta/worker_test.rb
|
45
|
+
- LICENSE
|
46
|
+
has_rdoc: true
|
47
|
+
homepage: http://github.com/dpickett/workling_delta_indexer
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options:
|
50
|
+
- --inline-source
|
51
|
+
- --charset=UTF-8
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: "0"
|
65
|
+
version:
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.2.0
|
70
|
+
signing_key:
|
71
|
+
specification_version: 2
|
72
|
+
summary: TODO
|
73
|
+
test_files: []
|
74
|
+
|