picky 1.1.2 → 1.1.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/sources/couch.rb +18 -1
- data/spec/lib/sources/couch_spec.rb +3 -3
- metadata +3 -3
data/lib/picky/sources/couch.rb
CHANGED
@@ -9,6 +9,21 @@ module Sources
|
|
9
9
|
|
10
10
|
# A Couch database source.
|
11
11
|
#
|
12
|
+
# <b>IMPORTANT NOTE:
|
13
|
+
#
|
14
|
+
# Since Picky currently only handles integer ids (we're working on this),
|
15
|
+
# and CouchDB uses hexadecimal ids, this source automatically
|
16
|
+
# recalculates a couch id such as
|
17
|
+
# fa3f2577a8dbc6a91d7f9989cdffd38e
|
18
|
+
# into
|
19
|
+
# 332634873577882511228481564366832915342
|
20
|
+
# using String#hex.
|
21
|
+
#
|
22
|
+
# When using the integer ids in a webapp to get your
|
23
|
+
# objects from CouchDB, please do a Integer#to_s(16) on the
|
24
|
+
# ids you get from Picky before you use them to get your object from CouchDB.</b>
|
25
|
+
#
|
26
|
+
#
|
12
27
|
# Options:
|
13
28
|
# * url
|
14
29
|
# and all the options of a <tt>RestClient::Resource</tt>.
|
@@ -37,10 +52,12 @@ module Sources
|
|
37
52
|
|
38
53
|
# Harvests the data to index.
|
39
54
|
#
|
55
|
+
# See important note, above.
|
56
|
+
#
|
40
57
|
def harvest type, category
|
41
58
|
category_name = category.from.to_s
|
42
59
|
get_data do |doc|
|
43
|
-
yield doc['_id'].
|
60
|
+
yield doc['_id'].hex, doc[category_name] || next
|
44
61
|
end
|
45
62
|
end
|
46
63
|
|
@@ -11,14 +11,14 @@ describe Sources::Couch do
|
|
11
11
|
context "with database" do
|
12
12
|
before(:each) do
|
13
13
|
@source = Sources::Couch.new :a, :b, :c, url: 'http://localhost:5984/picky'
|
14
|
-
RestClient::Request.should_receive(:execute).any_number_of_times.and_return %{{"rows":[{"doc":{"_id":"
|
14
|
+
RestClient::Request.should_receive(:execute).any_number_of_times.and_return %{{"rows":[{"doc":{"_id":"7f","a":"a data","b":"b data","c":"c data"}}]}}
|
15
15
|
end
|
16
16
|
|
17
17
|
describe "harvest" do
|
18
18
|
it "yields the right data" do
|
19
19
|
field = stub :b, :from => :b
|
20
20
|
@source.harvest :anything, field do |id, token|
|
21
|
-
id.should eql(
|
21
|
+
id.should eql(127)
|
22
22
|
token.should eql('b data')
|
23
23
|
end.should have(1).item
|
24
24
|
end
|
@@ -27,7 +27,7 @@ describe Sources::Couch do
|
|
27
27
|
describe "get_data" do
|
28
28
|
it "yields each line" do
|
29
29
|
@source.get_data do |data|
|
30
|
-
data.should == { "_id" => "
|
30
|
+
data.should == { "_id" => "7f", "a" => "a data", "b" => "b data", "c" => "c data" }
|
31
31
|
end.should have(1).item
|
32
32
|
end
|
33
33
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 1.1.
|
8
|
+
- 3
|
9
|
+
version: 1.1.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-13 00:00:00 +01:00
|
18
18
|
default_executable: picky
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|