picky 4.12.6 → 4.12.7

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.
@@ -7,6 +7,8 @@ module Picky
7
7
  forward :each,
8
8
  :first,
9
9
  :map,
10
+ :map!,
11
+ :include?,
10
12
  :to => :categories
11
13
 
12
14
  each_forward :cache,
@@ -51,7 +53,7 @@ module Picky
51
53
  #
52
54
  def << category
53
55
  reset_qualifier_mapper # TODO Have an add method on QualifierMapper?
54
- categories << category
56
+ categories << category unless categories.include? category # This is wrong, and needs to be handled in index.rb
55
57
  category_hash[category.name] = category
56
58
  end
57
59
 
@@ -9,7 +9,11 @@ module Picky
9
9
  :clear_realtime,
10
10
  :build_realtime_mapping,
11
11
  :to => :categories
12
-
12
+
13
+ def update object, where = :unshift
14
+ replace object, where = :unshift
15
+ end
16
+
13
17
  end
14
18
 
15
19
  end
@@ -167,6 +167,14 @@ module Picky
167
167
  def identifier
168
168
  :"#{@index.identifier}:#{name}"
169
169
  end
170
+
171
+ # Uniquely identified by index name and name.
172
+ #
173
+ def == other
174
+ return false unless other
175
+ index_name == other.index_name &&
176
+ name == other.name
177
+ end
170
178
 
171
179
  #
172
180
  #
@@ -32,7 +32,7 @@ module Picky
32
32
  #
33
33
  # Note: Takes a hash as opposed to the add/replace method.
34
34
  #
35
- def replace_from hash
35
+ def replace_from hash #, id = (hash[:id] || hash['id'] || raise(IdNotGivenException.new)).send(key_format)
36
36
  return unless text = hash[from] || hash[from.to_s]
37
37
 
38
38
  raise IdNotGivenException.new unless id = hash[:id] || hash['id']
@@ -6,7 +6,8 @@ module Picky
6
6
 
7
7
  forward :remove, # aka "delete".
8
8
  :add, # aka "insert".
9
- :replace, # aka "insert or update". Thus, not called update.
9
+ :replace, # aka "delete then insert".
10
+ :update,
10
11
  :replace_from,
11
12
  :clear_realtime,
12
13
  :build_realtime_mapping,
data/lib/picky/indexes.rb CHANGED
@@ -47,6 +47,9 @@ module Picky
47
47
  # Registers an index with the indexes.
48
48
  #
49
49
  def register index
50
+ # TODO DO not store duplicate indexes.
51
+ #
52
+ # self.indexes.delete_if { |existing| existing.name == index.name }
50
53
  self.indexes << index
51
54
  self.index_mapping[index.name] = index
52
55
  end
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+ #
3
+ require 'spec_helper'
4
+
5
+ describe "Error messages for" do
6
+
7
+ context 'missing category method' do
8
+ let(:index) do
9
+ Picky::Index.new :error_messages do
10
+ category :author
11
+ category :title
12
+ end
13
+ end
14
+ let(:thing) { Struct.new :id, :author } # It is missing the title.
15
+ it 'is informative when dynamic indexing' do
16
+ this = thing.new 1, "ohai"
17
+
18
+ # For now, a NoMethodError is enough.
19
+ #
20
+ expect { index.add this }.to raise_error(NoMethodError)
21
+ end
22
+ it 'is informative when static indexing' do
23
+ thing = Struct.new :id, :author
24
+
25
+ index.source [thing.new(1, "ohai")]
26
+
27
+ # For now, a NoMethodError is enough.
28
+ #
29
+ expect { index.index }.to raise_error(NoMethodError)
30
+ end
31
+ end
32
+
33
+ end
@@ -22,6 +22,21 @@ describe Picky::Category do
22
22
 
23
23
  category.instance_variable_get(:@symbols).should == nil
24
24
  end
25
+
26
+ context '#==' do
27
+ it 'is identical on the same thing' do
28
+ category.should == category
29
+ end
30
+ it 'looks only at index name and category name' do
31
+ category.should == described_class.new(:some_category, index)
32
+ end
33
+ it 'looks only at index name and category name' do
34
+ category.should_not == described_class.new(:some_other_category, index)
35
+ end
36
+ it 'results in a correct #include?' do
37
+ [category].include?(described_class.new(:some_category, index)).should == true
38
+ end
39
+ end
25
40
  end
26
41
 
27
42
  context 'directories' do
@@ -2,7 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe Picky::Indexes do
4
4
 
5
- let(:index) { stub :some_index, :name => :some_index }
5
+ let(:index) { stub :some_index, :name => :some_index }
6
+ let(:index2) { stub :some_index2, :name => :some_index }
6
7
 
7
8
  context 'with instance' do
8
9
  let(:indexes) { Picky::Indexes.new }
@@ -44,6 +45,14 @@ describe Picky::Indexes do
44
45
 
45
46
  indexes.indexes.should == [index]
46
47
  end
48
+ # it 'does remove duplicates (with same name)' do
49
+ # indexes.clear_indexes
50
+ #
51
+ # indexes.register index
52
+ # indexes.register index2
53
+ #
54
+ # indexes.indexes.should == [index2]
55
+ # end
47
56
  end
48
57
  end
49
58
 
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.6
4
+ version: 4.12.7
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-01-02 00:00:00.000000000 Z
12
+ date: 2013-01-14 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.6
37
+ version: 4.12.7
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.6
45
+ version: 4.12.7
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: text
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -278,6 +278,7 @@ files:
278
278
  - spec/functional/backends/sqlite_spec.rb
279
279
  - spec/functional/custom_delimiters_spec.rb
280
280
  - spec/functional/dynamic_weights_spec.rb
281
+ - spec/functional/error_messages_spec.rb
281
282
  - spec/functional/exact_first_spec.rb
282
283
  - spec/functional/facets_spec.rb
283
284
  - spec/functional/ignore_spec.rb
@@ -446,6 +447,7 @@ test_files:
446
447
  - spec/functional/backends/sqlite_spec.rb
447
448
  - spec/functional/custom_delimiters_spec.rb
448
449
  - spec/functional/dynamic_weights_spec.rb
450
+ - spec/functional/error_messages_spec.rb
449
451
  - spec/functional/exact_first_spec.rb
450
452
  - spec/functional/facets_spec.rb
451
453
  - spec/functional/ignore_spec.rb