picky 4.12.13 → 4.13.0

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.
@@ -53,7 +53,7 @@ module Picky
53
53
  #
54
54
  def << category
55
55
  reset_qualifier_mapper # TODO Have an add method on QualifierMapper?
56
- categories << category unless categories.include? category # This is wrong, and needs to be handled in index.rb
56
+ categories << category unless categories.include? category # TODO This is wrong, and needs to be handled in index.rb
57
57
  category_hash[category.name] = category
58
58
  end
59
59
 
@@ -59,8 +59,6 @@ module Picky
59
59
  #
60
60
  # Note: Once I thought this was called too often. But it is not (18.01.2011).
61
61
  #
62
- # TODO Called too often?
63
- #
64
62
  def possible_categories token
65
63
  token.predefined_categories(qualifier_mapper) || categories
66
64
  end
@@ -42,7 +42,7 @@ module Picky
42
42
  end
43
43
 
44
44
  def configure_from options
45
- @from = options[:from]
45
+ @from = options.delete :from
46
46
 
47
47
  # Instantly extracted to raise an error instantly.
48
48
  #
@@ -61,6 +61,8 @@ module Picky
61
61
  # TODO I do a lot of helper method calls here. Refactor?
62
62
  #
63
63
  def configure_indexes_from options
64
+ warn_if_unknown options
65
+
64
66
  weights = weights_from options
65
67
  partial = partial_from options
66
68
  similarity = similarity_from options
@@ -70,6 +72,20 @@ module Picky
70
72
 
71
73
  @prepared = Backends::Prepared::Text.new prepared_index_path
72
74
  end
75
+ # Since the options hash might contain options that do not exist,
76
+ # we should warn people if they use the wrong options.
77
+ # (Problem is that if the option is not found, then Picky will use the default)
78
+ #
79
+ # TODO Rewrite it such that this does not need to be maintained separately.
80
+ #
81
+ @@known_keys = [:indexing, :partial, :qualifier, :qualifiers, :ranging, :similarity, :source, :weight]
82
+ def warn_if_unknown options
83
+ warn <<-WARNING if options && (options.keys - @@known_keys).size > 0
84
+
85
+ Warning: Category options #{options} for category #{name} contain an unknown option.
86
+ Working options are: #{@@known_keys}.
87
+ WARNING
88
+ end
73
89
  def weights_from options
74
90
  Generators::Weights.from options[:weight], index_name, name
75
91
  end
data/lib/picky.rb CHANGED
@@ -18,7 +18,7 @@ module Picky
18
18
 
19
19
  # External libraries.
20
20
  #
21
- # TODO Remove active support.
21
+ # TODO Remove active support, as a goal.
22
22
  #
23
23
  require 'active_support/core_ext/logger'
24
24
  require 'active_support/core_ext/object/blank'
@@ -7,14 +7,14 @@ describe Picky::Category do
7
7
  source []
8
8
  end
9
9
  @partial_strategy = stub :partial, :each_partial => nil, :use_exact_for_partial? => false
10
- @weight_strategy = stub :weights, :saved? => true
10
+ @weight_strategy = stub :weights, :saved? => true, :weight_for => :some_weight
11
11
  @similarity_strategy = stub :similarity, :encode => nil, :prioritize => nil
12
12
 
13
13
  @exact = stub :exact, :dump => nil
14
14
  @partial = stub :partial, :dump => nil
15
15
 
16
16
  @category = described_class.new :some_name, @index, :partial => @partial_strategy,
17
- :weights => @weight_strategy,
17
+ :weight => @weight_strategy,
18
18
  :similarity => @similarity_strategy,
19
19
  :qualifiers => [:q, :qualifier]
20
20
 
@@ -45,6 +45,24 @@ describe Picky::Category do
45
45
  category.prepared_index_path.should == 'spec/temp/index/test/some_index/some_category'
46
46
  end
47
47
  end
48
+
49
+ describe 'options' do
50
+ let(:category) { described_class.new :some_category, index }
51
+ it 'warns on wrong options' do
52
+ category.should_receive(:warn).once.with <<-WARNING
53
+
54
+ Warning: Category options {:weights=>:some_weight} for category some_category contain an unknown option.
55
+ Working options are: [:indexing, :partial, :qualifier, :qualifiers, :ranging, :similarity, :source, :weight].
56
+ WARNING
57
+
58
+ category.warn_if_unknown :weights => :some_weight
59
+ end
60
+ it 'does not warn on right options' do
61
+ category.should_receive(:warn).never
62
+
63
+ category.warn_if_unknown :weight => :some_weight
64
+ end
65
+ end
48
66
 
49
67
  context 'tokenizer' do
50
68
  context 'options hash' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: picky
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.12.13
4
+ version: 4.13.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-08 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 4.12.13
37
+ version: 4.13.0
38
38
  type: :development
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 4.12.13
45
+ version: 4.13.0
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: text
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -128,7 +128,6 @@ files:
128
128
  - lib/picky/backends/file/json.rb
129
129
  - lib/picky/backends/file.rb
130
130
  - lib/picky/backends/helpers/file.rb
131
- - lib/picky/backends/internal.rb
132
131
  - lib/picky/backends/memory/basic.rb
133
132
  - lib/picky/backends/memory/json.rb
134
133
  - lib/picky/backends/memory/marshal.rb
@@ -1,23 +0,0 @@
1
- module Picky
2
-
3
- module Backends
4
-
5
- module Internal
6
-
7
- # Nothing needs to be deleted from it.
8
- #
9
- def delete _
10
-
11
- end
12
-
13
- # It does not need to be cleared.
14
- #
15
- def clear
16
-
17
- end
18
-
19
- end
20
-
21
- end
22
-
23
- end