picky 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/picky/cacher/partial/default.rb +1 -1
- data/lib/picky/cacher/partial/subtoken.rb +18 -18
- data/lib/picky/cacher/partial_generator.rb +1 -1
- data/lib/picky/extensions/hash.rb +4 -4
- data/lib/picky/extensions/symbol.rb +9 -9
- data/lib/picky/index/bundle.rb +58 -133
- data/lib/picky/index/file/basic.rb +67 -0
- data/lib/picky/index/file/json.rb +24 -0
- data/lib/picky/index/file/marshal.rb +24 -0
- data/lib/picky/index/file/text.rb +28 -0
- data/lib/picky/index/files.rb +135 -0
- data/lib/picky/indexers/base.rb +4 -0
- data/lib/picky/indexes.rb +2 -2
- data/lib/picky/loader.rb +8 -2
- data/lib/picky/sources/delicious.rb +7 -1
- data/project_prototype/app/application.rb +9 -7
- data/spec/lib/cacher/partial/default_spec.rb +3 -3
- data/spec/lib/cacher/partial/subtoken_spec.rb +28 -28
- data/spec/lib/cacher/partial_generator_spec.rb +2 -2
- data/spec/lib/extensions/hash_spec.rb +4 -4
- data/spec/lib/index/bundle_partial_generation_speed_spec.rb +1 -1
- data/spec/lib/index/bundle_spec.rb +47 -46
- data/spec/lib/index/file/basic_spec.rb +15 -0
- data/spec/lib/index/file/json_spec.rb +26 -0
- data/spec/lib/index/file/marshal_spec.rb +26 -0
- data/spec/lib/index/file/text_spec.rb +27 -0
- data/spec/lib/index/files_spec.rb +186 -0
- data/spec/lib/index/type_spec.rb +5 -2
- data/spec/lib/query/combinator_spec.rb +5 -3
- data/spec/lib/sources/delicious_spec.rb +9 -1
- metadata +18 -6
- data/lib/picky/index/bundle_checker.rb +0 -58
- data/spec/lib/index/bundle_checker_spec.rb +0 -67
@@ -0,0 +1,186 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Index::Files do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@files_class = Index::Files
|
7
|
+
@files = @files_class.new :some_name, :some_category, :some_type
|
8
|
+
|
9
|
+
@prepared = @files.prepared
|
10
|
+
|
11
|
+
@index = @files.index
|
12
|
+
@similarity = @files.similarity
|
13
|
+
@weights = @files.weights
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'create_directory' do
|
17
|
+
it 'should use makedirs to create the necessary directory structure' do
|
18
|
+
FileUtils.should_receive(:mkdir_p).once.with 'some/search/root/index/test/some_type'
|
19
|
+
|
20
|
+
@files.create_directory
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'cache_directory' do
|
25
|
+
it 'should be correct' do
|
26
|
+
@files.cache_directory.should == 'some/search/root/index/test/some_type'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "retrieve" do
|
31
|
+
it "delegates to the prepared" do
|
32
|
+
@prepared.should_receive(:retrieve).once.with
|
33
|
+
|
34
|
+
@files.retrieve
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "dump indexes" do
|
39
|
+
describe "dump_index" do
|
40
|
+
it "uses the right file" do
|
41
|
+
@index.should_receive(:dump).once.with :some_hash
|
42
|
+
|
43
|
+
@files.dump_index :some_hash
|
44
|
+
end
|
45
|
+
end
|
46
|
+
describe "dump_similarity" do
|
47
|
+
it "uses the right file" do
|
48
|
+
@similarity.should_receive(:dump).once.with :some_hash
|
49
|
+
|
50
|
+
@files.dump_similarity :some_hash
|
51
|
+
end
|
52
|
+
end
|
53
|
+
describe "dump_weights" do
|
54
|
+
it "uses the right file" do
|
55
|
+
@weights.should_receive(:dump).once.with :some_hash
|
56
|
+
|
57
|
+
@files.dump_weights :some_hash
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "loading indexes" do
|
63
|
+
before(:each) do
|
64
|
+
@files.stub! :timed_exclaim
|
65
|
+
end
|
66
|
+
describe "load_index" do
|
67
|
+
it "uses the right file" do
|
68
|
+
Yajl::Parser.stub! :parse
|
69
|
+
|
70
|
+
File.should_receive(:open).once.with 'some/search/root/index/test/some_type/some_name_some_category_index.json', 'r'
|
71
|
+
|
72
|
+
@files.load_index
|
73
|
+
end
|
74
|
+
end
|
75
|
+
describe "load_similarity" do
|
76
|
+
it "uses the right file" do
|
77
|
+
Marshal.stub! :load
|
78
|
+
|
79
|
+
File.should_receive(:open).once.with 'some/search/root/index/test/some_type/some_name_some_category_similarity.dump', 'r:binary'
|
80
|
+
|
81
|
+
@files.load_similarity
|
82
|
+
end
|
83
|
+
end
|
84
|
+
describe "load_weights" do
|
85
|
+
it "uses the right file" do
|
86
|
+
Yajl::Parser.stub! :parse
|
87
|
+
|
88
|
+
File.should_receive(:open).once.with 'some/search/root/index/test/some_type/some_name_some_category_weights.json', 'r'
|
89
|
+
|
90
|
+
@files.load_weights
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "dump indexes" do
|
96
|
+
describe "index_cache_ok?" do
|
97
|
+
it "uses the right method" do
|
98
|
+
@index.should_receive(:cache_ok?).once.with
|
99
|
+
|
100
|
+
@files.index_cache_ok?
|
101
|
+
end
|
102
|
+
end
|
103
|
+
describe "similarity_cache_ok?" do
|
104
|
+
it "uses the right method" do
|
105
|
+
@similarity.should_receive(:cache_ok?).once.with
|
106
|
+
|
107
|
+
@files.similarity_cache_ok?
|
108
|
+
end
|
109
|
+
end
|
110
|
+
describe "weights_cache_ok?" do
|
111
|
+
it "uses the right method" do
|
112
|
+
@weights.should_receive(:cache_ok?).once.with
|
113
|
+
|
114
|
+
@files.weights_cache_ok?
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe "dump indexes" do
|
120
|
+
describe "index_cache_small?" do
|
121
|
+
it "uses the right method" do
|
122
|
+
@index.should_receive(:cache_small?).once.with
|
123
|
+
|
124
|
+
@files.index_cache_small?
|
125
|
+
end
|
126
|
+
end
|
127
|
+
describe "similarity_cache_small?" do
|
128
|
+
it "uses the right method" do
|
129
|
+
@similarity.should_receive(:cache_small?).once.with
|
130
|
+
|
131
|
+
@files.similarity_cache_small?
|
132
|
+
end
|
133
|
+
end
|
134
|
+
describe "weights_cache_small?" do
|
135
|
+
it "uses the right method" do
|
136
|
+
@weights.should_receive(:cache_small?).once.with
|
137
|
+
|
138
|
+
@files.weights_cache_small?
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe 'backup' do
|
144
|
+
it 'should call backup on all' do
|
145
|
+
@index.should_receive(:backup).once.with
|
146
|
+
@similarity.should_receive(:backup).once.with
|
147
|
+
@weights.should_receive(:backup).once.with
|
148
|
+
|
149
|
+
@files.backup
|
150
|
+
end
|
151
|
+
end
|
152
|
+
describe 'restore' do
|
153
|
+
it 'should call delete on all' do
|
154
|
+
@index.should_receive(:restore).once.with
|
155
|
+
@similarity.should_receive(:restore).once.with
|
156
|
+
@weights.should_receive(:restore).once.with
|
157
|
+
|
158
|
+
@files.restore
|
159
|
+
end
|
160
|
+
end
|
161
|
+
describe 'delete' do
|
162
|
+
it 'should call delete on all' do
|
163
|
+
@index.should_receive(:delete).once.with
|
164
|
+
@similarity.should_receive(:delete).once.with
|
165
|
+
@weights.should_receive(:delete).once.with
|
166
|
+
|
167
|
+
@files.delete
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe 'initialization' do
|
172
|
+
before(:each) do
|
173
|
+
@files = @files_class.new :some_name, :some_category, :some_type
|
174
|
+
end
|
175
|
+
it 'should initialize the name correctly' do
|
176
|
+
@files.bundle_name.should == :some_name
|
177
|
+
end
|
178
|
+
it 'should initialize the name correctly' do
|
179
|
+
@files.category_name.should == :some_category
|
180
|
+
end
|
181
|
+
it 'should initialize the name correctly' do
|
182
|
+
@files.type_name.should == :some_type
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
end
|
data/spec/lib/index/type_spec.rb
CHANGED
@@ -4,8 +4,11 @@ describe Index::Type do
|
|
4
4
|
|
5
5
|
context "with categories" do
|
6
6
|
before(:each) do
|
7
|
-
@
|
8
|
-
@
|
7
|
+
@some_type1 = stub :some_type1, :name => :some_type1
|
8
|
+
@some_type2 = stub :some_type2, :name => :some_type2
|
9
|
+
|
10
|
+
@category1 = Index::Category.new :some_category_name1, @some_type1
|
11
|
+
@category2 = Index::Category.new :some_category_name2, @some_type2
|
9
12
|
|
10
13
|
@index = Index::Type.new :some_name, :some_result_type, false, @category1, @category2
|
11
14
|
end
|
@@ -29,9 +29,11 @@ describe Query::Combinator do
|
|
29
29
|
|
30
30
|
context "with real categories" do
|
31
31
|
before(:each) do
|
32
|
-
@
|
33
|
-
|
34
|
-
@
|
32
|
+
@type1 = stub :type1, :name => :some_type
|
33
|
+
|
34
|
+
@category1 = Index::Category.new :some_name, @type1
|
35
|
+
@category2 = Index::Category.new :some_name, @type1
|
36
|
+
@category3 = Index::Category.new :some_name, @type1
|
35
37
|
@categories = [@category1, @category2, @category3]
|
36
38
|
|
37
39
|
@combinator = Query::Combinator.new @categories
|
@@ -3,7 +3,15 @@ require 'spec_helper'
|
|
3
3
|
describe Sources::Delicious do
|
4
4
|
|
5
5
|
context "with file" do
|
6
|
-
|
6
|
+
|
7
|
+
describe "check_gem" do
|
8
|
+
# TODO How to actually test this?
|
9
|
+
#
|
10
|
+
it "checks if the gem is there" do
|
11
|
+
lambda { Sources::Delicious.new(:username, :password) }.should_not raise_error
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
7
15
|
describe "harvest" do
|
8
16
|
before(:each) do
|
9
17
|
@source = Sources::Delicious.new(:username, :password)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 1
|
9
|
+
version: 0.9.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Florian Hanke
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-27 00:00:00 +02:00
|
18
18
|
default_executable: picky
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -75,8 +75,12 @@ files:
|
|
75
75
|
- lib/picky/helpers/gc.rb
|
76
76
|
- lib/picky/helpers/measuring.rb
|
77
77
|
- lib/picky/index/bundle.rb
|
78
|
-
- lib/picky/index/bundle_checker.rb
|
79
78
|
- lib/picky/index/category.rb
|
79
|
+
- lib/picky/index/file/basic.rb
|
80
|
+
- lib/picky/index/file/json.rb
|
81
|
+
- lib/picky/index/file/marshal.rb
|
82
|
+
- lib/picky/index/file/text.rb
|
83
|
+
- lib/picky/index/files.rb
|
80
84
|
- lib/picky/index/type.rb
|
81
85
|
- lib/picky/index/wrappers/exact_first.rb
|
82
86
|
- lib/picky/indexers/base.rb
|
@@ -169,10 +173,14 @@ files:
|
|
169
173
|
- spec/lib/helpers/cache_spec.rb
|
170
174
|
- spec/lib/helpers/gc_spec.rb
|
171
175
|
- spec/lib/helpers/measuring_spec.rb
|
172
|
-
- spec/lib/index/bundle_checker_spec.rb
|
173
176
|
- spec/lib/index/bundle_partial_generation_speed_spec.rb
|
174
177
|
- spec/lib/index/bundle_spec.rb
|
175
178
|
- spec/lib/index/category_spec.rb
|
179
|
+
- spec/lib/index/file/basic_spec.rb
|
180
|
+
- spec/lib/index/file/json_spec.rb
|
181
|
+
- spec/lib/index/file/marshal_spec.rb
|
182
|
+
- spec/lib/index/file/text_spec.rb
|
183
|
+
- spec/lib/index/files_spec.rb
|
176
184
|
- spec/lib/index/type_spec.rb
|
177
185
|
- spec/lib/index/wrappers/exact_first_spec.rb
|
178
186
|
- spec/lib/indexers/base_spec.rb
|
@@ -265,10 +273,14 @@ test_files:
|
|
265
273
|
- spec/lib/helpers/cache_spec.rb
|
266
274
|
- spec/lib/helpers/gc_spec.rb
|
267
275
|
- spec/lib/helpers/measuring_spec.rb
|
268
|
-
- spec/lib/index/bundle_checker_spec.rb
|
269
276
|
- spec/lib/index/bundle_partial_generation_speed_spec.rb
|
270
277
|
- spec/lib/index/bundle_spec.rb
|
271
278
|
- spec/lib/index/category_spec.rb
|
279
|
+
- spec/lib/index/file/basic_spec.rb
|
280
|
+
- spec/lib/index/file/json_spec.rb
|
281
|
+
- spec/lib/index/file/marshal_spec.rb
|
282
|
+
- spec/lib/index/file/text_spec.rb
|
283
|
+
- spec/lib/index/files_spec.rb
|
272
284
|
- spec/lib/index/type_spec.rb
|
273
285
|
- spec/lib/index/wrappers/exact_first_spec.rb
|
274
286
|
- spec/lib/indexers/base_spec.rb
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
module Index
|
4
|
-
|
5
|
-
# Checks bundle indexes.
|
6
|
-
#
|
7
|
-
class BundleChecker
|
8
|
-
|
9
|
-
attr_reader :bundle
|
10
|
-
|
11
|
-
def initialize bundle
|
12
|
-
@bundle = bundle
|
13
|
-
end
|
14
|
-
|
15
|
-
# Check all index files and raise if necessary.
|
16
|
-
#
|
17
|
-
def raise_unless_cache_exists
|
18
|
-
warn_cache_small :index if cache_small?(bundle.index_cache_path)
|
19
|
-
# warn_cache_small :similarity if cache_small?(similarity_cache_path)
|
20
|
-
warn_cache_small :weights if cache_small?(bundle.weights_cache_path)
|
21
|
-
|
22
|
-
raise_cache_missing :index unless cache_ok?(bundle.index_cache_path)
|
23
|
-
raise_cache_missing :similarity unless cache_ok?(bundle.similarity_cache_path)
|
24
|
-
raise_cache_missing :weights unless cache_ok?(bundle.weights_cache_path)
|
25
|
-
end
|
26
|
-
|
27
|
-
def size_of path
|
28
|
-
`ls -l #{path} | awk '{print $5}'`.to_i
|
29
|
-
end
|
30
|
-
# Check if the cache files are there and do not have size 0.
|
31
|
-
#
|
32
|
-
def caches_ok?
|
33
|
-
cache_ok?(bundle.index_cache_path) &&
|
34
|
-
cache_ok?(bundle.similarity_cache_path) &&
|
35
|
-
cache_ok?(bundle.weights_cache_path)
|
36
|
-
end
|
37
|
-
# Is the cache ok? I.e. larger than four in size.
|
38
|
-
#
|
39
|
-
def cache_ok? path
|
40
|
-
size_of(path) > 0
|
41
|
-
end
|
42
|
-
# Raises an appropriate error message.
|
43
|
-
#
|
44
|
-
def raise_cache_missing what
|
45
|
-
raise "#{what} cache for #{bundle.identifier} missing."
|
46
|
-
end
|
47
|
-
# Is the cache small?
|
48
|
-
#
|
49
|
-
def cache_small? path
|
50
|
-
size_of(path) < 16
|
51
|
-
end
|
52
|
-
def warn_cache_small what
|
53
|
-
puts "#{what} cache for #{bundle.identifier} smaller than 16 bytes."
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Index::BundleChecker do
|
4
|
-
|
5
|
-
before(:each) do
|
6
|
-
@category = stub :category, :name => :some_category
|
7
|
-
@type = stub :type, :name => :some_type
|
8
|
-
@partial = stub :partial
|
9
|
-
@weights = stub :weights
|
10
|
-
@similarity = stub :similarity
|
11
|
-
@index_class = Index::Bundle
|
12
|
-
@index = @index_class.new :some_name, @category, @type, @partial, @weights, @similarity
|
13
|
-
|
14
|
-
@checker = @index.checker
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'raise_unless_cache_exists' do
|
18
|
-
before(:each) do
|
19
|
-
@checker.stub! :cache_small? => false
|
20
|
-
end
|
21
|
-
context 'weights cache missing' do
|
22
|
-
before(:each) do
|
23
|
-
@checker.stub! :cache_ok? => true
|
24
|
-
@index.stub! :weights_cache_path => 'weights_cache_path'
|
25
|
-
@checker.should_receive(:cache_ok?).any_number_of_times.with('weights_cache_path').and_return false
|
26
|
-
end
|
27
|
-
it 'should raise' do
|
28
|
-
lambda do
|
29
|
-
@checker.raise_unless_cache_exists
|
30
|
-
end.should raise_error("weights cache for some_name: some_type some_category missing.")
|
31
|
-
end
|
32
|
-
end
|
33
|
-
context 'similarity cache missing' do
|
34
|
-
before(:each) do
|
35
|
-
@checker.stub! :cache_ok? => true
|
36
|
-
@index.stub! :similarity_cache_path => 'similarity_cache_path'
|
37
|
-
@checker.should_receive(:cache_ok?).any_number_of_times.with('similarity_cache_path').and_return false
|
38
|
-
end
|
39
|
-
it 'should raise' do
|
40
|
-
lambda do
|
41
|
-
@checker.raise_unless_cache_exists
|
42
|
-
end.should raise_error("similarity cache for some_name: some_type some_category missing.")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
context 'index cache missing' do
|
46
|
-
before(:each) do
|
47
|
-
@checker.stub! :cache_ok? => true
|
48
|
-
@index.stub! :index_cache_path => 'index_cache_path'
|
49
|
-
@checker.should_receive(:cache_ok?).any_number_of_times.with('index_cache_path').and_return false
|
50
|
-
end
|
51
|
-
it 'should raise' do
|
52
|
-
lambda do
|
53
|
-
@checker.raise_unless_cache_exists
|
54
|
-
end.should raise_error("index cache for some_name: some_type some_category missing.")
|
55
|
-
end
|
56
|
-
end
|
57
|
-
context 'all ok' do
|
58
|
-
before(:each) do
|
59
|
-
@checker.stub! :cache_ok? => true
|
60
|
-
end
|
61
|
-
it 'should not raise' do
|
62
|
-
lambda { @checker.raise_unless_cache_exists }.should_not raise_error
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|