picky 1.2.2 → 1.2.3
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/none.rb +6 -0
- data/lib/picky/cacher/partial/strategy.rb +12 -0
- data/lib/picky/indexed/category.rb +11 -1
- data/lib/picky/routing.rb +9 -0
- data/spec/lib/cacher/partial/none_spec.rb +5 -0
- data/spec/lib/cacher/partial/substring_spec.rb +5 -0
- data/spec/lib/indexed/category_spec.rb +28 -11
- data/spec/lib/routing_spec.rb +3 -0
- metadata +3 -3
@@ -4,6 +4,18 @@ module Cacher
|
|
4
4
|
#
|
5
5
|
class Strategy < Cacher::Strategy
|
6
6
|
|
7
|
+
# Defines whether to use the exact bundle
|
8
|
+
# instead of the partial one.
|
9
|
+
#
|
10
|
+
# Default is @false@.
|
11
|
+
#
|
12
|
+
# For example:
|
13
|
+
# Partial::None.new # Uses the exact index instead of the partial one.
|
14
|
+
#
|
15
|
+
def use_exact_for_partial?
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
7
19
|
end
|
8
20
|
end
|
9
21
|
end
|
@@ -7,8 +7,9 @@ module Indexed
|
|
7
7
|
#
|
8
8
|
class Category
|
9
9
|
|
10
|
-
attr_accessor :exact
|
10
|
+
attr_accessor :exact
|
11
11
|
attr_reader :identifier, :name
|
12
|
+
attr_writer :partial
|
12
13
|
|
13
14
|
#
|
14
15
|
#
|
@@ -19,6 +20,9 @@ module Indexed
|
|
19
20
|
|
20
21
|
@identifier = configuration.identifier
|
21
22
|
|
23
|
+
# TODO Push the defaults out into the index.
|
24
|
+
#
|
25
|
+
@partial_strategy = options[:partial] || Cacher::Partial::Default
|
22
26
|
similarity = options[:similarity] || Cacher::Similarity::Default
|
23
27
|
|
24
28
|
@exact = options[:exact_index_bundle] || Bundle.new(:exact, configuration, similarity)
|
@@ -64,6 +68,12 @@ module Indexed
|
|
64
68
|
token.partial? ? partial : exact
|
65
69
|
end
|
66
70
|
|
71
|
+
# The partial strategy defines whether to really use the partial index.
|
72
|
+
#
|
73
|
+
def partial
|
74
|
+
@partial_strategy.use_exact_for_partial?? @exact : @partial
|
75
|
+
end
|
76
|
+
|
67
77
|
#
|
68
78
|
#
|
69
79
|
def combination_for token
|
data/lib/picky/routing.rb
CHANGED
@@ -53,9 +53,18 @@ class Routing # :nodoc:all
|
|
53
53
|
[mappings, route_options]
|
54
54
|
end
|
55
55
|
def route_one url, query, route_options = {}
|
56
|
+
raise TargetQueryNilError.new(url) unless query
|
56
57
|
query.tokenizer = @defaults[:tokenizer] if @defaults[:tokenizer]
|
57
58
|
routes.add_route generate_app(query, route_options), default_options(url, route_options)
|
58
59
|
end
|
60
|
+
class TargetQueryNilError < StandardError
|
61
|
+
def initialize url
|
62
|
+
@url = url
|
63
|
+
end
|
64
|
+
def to_s
|
65
|
+
"Routing for #{@url.inspect} was defined with a nil query object."
|
66
|
+
end
|
67
|
+
end
|
59
68
|
#
|
60
69
|
#
|
61
70
|
def root status
|
@@ -8,5 +8,10 @@ describe Cacher::Partial::None do
|
|
8
8
|
it "returns an empty index" do
|
9
9
|
Cacher::Partial::None.new.generate_from(:unimportant).should == {}
|
10
10
|
end
|
11
|
+
describe 'use_exact_for_partial?' do
|
12
|
+
it 'returns true' do
|
13
|
+
Cacher::Partial::None.new.use_exact_for_partial?.should == true
|
14
|
+
end
|
15
|
+
end
|
11
16
|
|
12
17
|
end
|
@@ -6,6 +6,11 @@ describe Cacher::Partial::Substring do
|
|
6
6
|
before(:each) do
|
7
7
|
@cacher = Cacher::Partial::Substring.new
|
8
8
|
end
|
9
|
+
describe 'use_exact_for_partial?' do
|
10
|
+
it 'returns false' do
|
11
|
+
Cacher::Partial::Substring.new.use_exact_for_partial?.should == false
|
12
|
+
end
|
13
|
+
end
|
9
14
|
describe 'from' do
|
10
15
|
it 'should return the right value' do
|
11
16
|
@cacher.from.should == 1
|
@@ -3,23 +3,40 @@ require 'spec_helper'
|
|
3
3
|
describe Indexed::Category do
|
4
4
|
|
5
5
|
before(:each) do
|
6
|
-
@index
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@category = Indexed::Category.new :some_name, @index, :partial => @partial,
|
11
|
-
:weights => @weights,
|
12
|
-
:similarity => @similarity,
|
13
|
-
:qualifiers => [:q, :qualifier]
|
6
|
+
@index = stub :index, :name => :some_index
|
7
|
+
@partial_strategy = stub :partial, :use_exact_for_partial? => false
|
8
|
+
@weights_strategy = stub :weights
|
9
|
+
@similarity_strategy = stub :similarity
|
14
10
|
|
15
11
|
@exact = stub :exact, :dump => nil
|
16
|
-
@category.stub! :exact => @exact
|
17
|
-
|
18
12
|
@partial = stub :partial, :dump => nil
|
19
|
-
|
13
|
+
|
14
|
+
@category = Indexed::Category.new :some_name, @index, :partial => @partial_strategy,
|
15
|
+
:weights => @weights_strategy,
|
16
|
+
:similarity => @similarity_strategy,
|
17
|
+
:qualifiers => [:q, :qualifier],
|
18
|
+
:exact_index_bundle => @exact,
|
19
|
+
:partial_index_bundle => @partial
|
20
|
+
|
20
21
|
@category.stub! :exclaim
|
21
22
|
end
|
22
23
|
|
24
|
+
describe 'partial' do
|
25
|
+
context 'with a partial strategy that uses the exact index' do
|
26
|
+
before(:each) do
|
27
|
+
@partial_strategy.stub! :use_exact_for_partial? => true
|
28
|
+
end
|
29
|
+
it 'returns the partial index' do
|
30
|
+
@category.partial.should == @exact
|
31
|
+
end
|
32
|
+
end
|
33
|
+
context 'with a partial strategy that uses the partial index (default)' do
|
34
|
+
it 'returns the partial index' do
|
35
|
+
@category.partial.should == @partial
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
23
40
|
describe 'generate_qualifiers_from' do
|
24
41
|
context 'with qualifiers' do
|
25
42
|
it 'returns that' do
|
data/spec/lib/routing_spec.rb
CHANGED
@@ -178,6 +178,9 @@ describe Routing do
|
|
178
178
|
|
179
179
|
@routing.route %r{regexp1} => :query1, %r{regexp2} => :query2, :some => :option
|
180
180
|
end
|
181
|
+
it 'does not accept nil queries' do
|
182
|
+
lambda { @routing.route %r{some/regexp} => nil }.should raise_error(Routing::TargetQueryNilError, /Routing for \/some\\\/regexp\/ was defined with a nil query object/)
|
183
|
+
end
|
181
184
|
end
|
182
185
|
|
183
186
|
describe 'route_one' do
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 1.2.
|
8
|
+
- 3
|
9
|
+
version: 1.2.3
|
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-12-
|
17
|
+
date: 2010-12-28 00:00:00 +01:00
|
18
18
|
default_executable: picky
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|