workling_delta_indexer 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/.gitmodules +3 -0
- data/LICENSE +20 -0
- data/README.rdoc +30 -0
- data/Rakefile +57 -0
- data/VERSION.yml +4 -0
- data/lib/workling_delta/indexer.rb +19 -0
- data/lib/workling_delta/worker.rb +15 -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 +78 -0
data/.gitmodules
ADDED
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,30 @@
|
|
1
|
+
= workling_delta_indexer
|
2
|
+
|
3
|
+
Use workling to manage your delta indexing with <a href="http://freelancing-gods.com/">Pat Allan's</a> <a href="http://github.com/freelancing-god/thinking-sphinx/tree/master">Thinking Sphinx</a>
|
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
|
+
== Documentation
|
25
|
+
|
26
|
+
View the documentation at http://rdoc.info/projects/dpickett/workling_delta_indexer
|
27
|
+
|
28
|
+
== Copyright
|
29
|
+
|
30
|
+
Copyright (c) 2009 Dan Pickett. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "workling_delta_indexer"
|
8
|
+
gem.summary = %Q{workling delta indexing for thinking sphinx}
|
9
|
+
gem.email = "dpickett@enlightsolutions.com"
|
10
|
+
gem.homepage = "http://github.com/dpickett/workling_delta_indexer"
|
11
|
+
gem.authors = ["Dan Pickett"]
|
12
|
+
gem.add_dependency "freelancing-god-thinking-sphinx", ">= 1.1.5"
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/rdoctask'
|
20
|
+
Rake::RDocTask.new do |rdoc|
|
21
|
+
rdoc.rdoc_dir = 'rdoc'
|
22
|
+
rdoc.title = 'workling_delta_indexer'
|
23
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
24
|
+
rdoc.rdoc_files.include('README*', "LICENSE")
|
25
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
require "YARD"
|
30
|
+
YARD::Rake::YardocTask.new do |t|
|
31
|
+
end
|
32
|
+
rescue LoadError
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rake/testtask'
|
37
|
+
Rake::TestTask.new(:test) do |test|
|
38
|
+
test.libs << 'lib' << 'test'
|
39
|
+
test.pattern = 'test/**/*_test.rb'
|
40
|
+
test.verbose = false
|
41
|
+
end
|
42
|
+
|
43
|
+
begin
|
44
|
+
require 'rcov/rcovtask'
|
45
|
+
Rcov::RcovTask.new do |test|
|
46
|
+
test.libs << 'test'
|
47
|
+
test.pattern = 'test/**/*_test.rb'
|
48
|
+
test.verbose = true
|
49
|
+
end
|
50
|
+
rescue LoadError
|
51
|
+
task :rcov do
|
52
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
task :default => :test
|
data/VERSION.yml
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module WorklingDelta
|
2
|
+
# This is the class that that should be wired to your index configuration
|
3
|
+
# @example definition in an index
|
4
|
+
# define_index do |index|
|
5
|
+
# set_property :delta => WorklingDelta::Indexer
|
6
|
+
# end
|
7
|
+
class Indexer < ThinkingSphinx::Deltas::DefaultDelta
|
8
|
+
# Creates the worker that performs the delta indexing
|
9
|
+
# @param model the class of that triggered the delta
|
10
|
+
# @param instance the instance that changed (if applicable)
|
11
|
+
# @return [Boolean] should always return true
|
12
|
+
def do_index(model, instance = nil)
|
13
|
+
doc_id = instance ? instance.sphinx_document_id : nil
|
14
|
+
WorklingDelta::Worker.async_index(:index_name => delta_index_name(model), :document_id => doc_id)
|
15
|
+
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# The Worker that actually performs the delta indexing
|
2
|
+
# This class performs the indexing asyncronously for Workling configurations
|
3
|
+
class WorklingDelta::Worker < Workling::Base
|
4
|
+
#perform the index
|
5
|
+
#@option options [String] :index_name the name of the index to run the delta job on
|
6
|
+
#@option options [Integer, nil] :document_id the sphinx document id of the object that needs to be flagged as deleted
|
7
|
+
def index(options = {})
|
8
|
+
ThinkingSphinx::Deltas::DeltaJob.new(options[:index_name]).perform
|
9
|
+
|
10
|
+
if options[:document_id]
|
11
|
+
ThinkingSphinx::Deltas::FlagAsDeletedJob.new(options[:index_name],
|
12
|
+
options[:document_id]).perform
|
13
|
+
end
|
14
|
+
end
|
15
|
+
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,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: workling_delta_indexer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Pickett
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-26 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: freelancing-god-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
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- .gitmodules
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION.yml
|
41
|
+
- lib/workling_delta/indexer.rb
|
42
|
+
- lib/workling_delta/worker.rb
|
43
|
+
- lib/workling_delta_indexer.rb
|
44
|
+
- test/test_helper.rb
|
45
|
+
- test/workling_delta/indexer_test.rb
|
46
|
+
- test/workling_delta/worker_test.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://github.com/dpickett/workling_delta_indexer
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --charset=UTF-8
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.5
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: workling delta indexing for thinking sphinx
|
75
|
+
test_files:
|
76
|
+
- test/test_helper.rb
|
77
|
+
- test/workling_delta/indexer_test.rb
|
78
|
+
- test/workling_delta/worker_test.rb
|