picky 0.10.4 → 0.10.5
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/loader.rb +2 -1
- data/lib/picky/sources/couch.rb +43 -0
- data/spec/lib/sources/couch_spec.rb +35 -0
- data/spec/lib/sources/delicious_spec.rb +0 -12
- metadata +6 -3
data/lib/picky/loader.rb
CHANGED
@@ -217,6 +217,7 @@ module Loader
|
|
217
217
|
load_relative 'sources/db'
|
218
218
|
load_relative 'sources/csv'
|
219
219
|
load_relative 'sources/delicious'
|
220
|
+
load_relative 'sources/couch'
|
220
221
|
|
221
222
|
# Indexes.
|
222
223
|
#
|
@@ -247,4 +248,4 @@ module Loader
|
|
247
248
|
load_relative 'generator'
|
248
249
|
end
|
249
250
|
|
250
|
-
end
|
251
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Sources
|
2
|
+
|
3
|
+
# Describes a Couch database
|
4
|
+
# Give it a databse url and optionally username and password
|
5
|
+
#
|
6
|
+
|
7
|
+
class NoCouchDBGiven < StandardError; end
|
8
|
+
|
9
|
+
class Couch < Base
|
10
|
+
|
11
|
+
def initialize *field_names, options
|
12
|
+
check_gem
|
13
|
+
Hash === options && options[:url] || raise_no_db_given(field_names)
|
14
|
+
@db = RestClient::Resource.new options.delete(:url), options
|
15
|
+
end
|
16
|
+
|
17
|
+
def check_gem
|
18
|
+
require 'rest_client'
|
19
|
+
rescue LoadError
|
20
|
+
puts "Rest-client gem missing!\nTo use the CouchDB source, you need to:\n 1. Add the following line to Gemfile:\n gem 'rest-client'\n 2. Then, run:\n bundle update\n"
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
|
24
|
+
# Harvests the data to index.
|
25
|
+
#
|
26
|
+
def harvest type, field
|
27
|
+
get_data do |doc|
|
28
|
+
yield doc['_id'].to_i, doc[field.name.to_s] || next
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_data &block
|
33
|
+
resp = @db['_all_docs?include_docs=true'].get
|
34
|
+
JSON.parse(resp)['rows'].
|
35
|
+
map{|row| row['doc']}.
|
36
|
+
each &block
|
37
|
+
end
|
38
|
+
|
39
|
+
def raise_no_db_given field_names
|
40
|
+
raise NoCouchDBGiven.new field_names.join(', ')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Sources::Couch do
|
4
|
+
|
5
|
+
context "without database" do
|
6
|
+
it "should fail correctly" do
|
7
|
+
lambda { @source = Sources::Couch.new(:a, :b, :c) }.should raise_error(Sources::NoCouchDBGiven)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context "with database" do
|
12
|
+
before(:each) do
|
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":"7","a":"a data","b":"b data","c":"c data"}}]}}
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "harvest" do
|
18
|
+
it "should yield the right data" do
|
19
|
+
field = stub :b, :name => :b
|
20
|
+
@source.harvest :anything, field do |id, token|
|
21
|
+
id.should eql(7)
|
22
|
+
token.should eql('b data')
|
23
|
+
end.should have(1).item
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "get_data" do
|
28
|
+
it "should yield each line" do
|
29
|
+
@source.get_data do |data|
|
30
|
+
data.should == { "_id" => "7", "a" => "a data", "b" => "b data", "c" => "c data" }
|
31
|
+
end.should have(1).item
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -41,12 +41,6 @@ describe Sources::Delicious do
|
|
41
41
|
post1.title = "VIBRAM - FiveFingers"
|
42
42
|
post1.url = URI.parse('http://www.vibramfivefingers.it/')
|
43
43
|
|
44
|
-
# post2 = WWW::Delicious::Post.new
|
45
|
-
# post2.uid = "d0b16f4b7e998a3386052bc95ad0d695"
|
46
|
-
# post2.tags = ["floating", "title", "scrolling", "css", "javascript", "ui"]
|
47
|
-
# post2.title = "Floating Title when Scrolling"
|
48
|
-
# post2.url = URI.parse('http://mesh.scribblelive.com/Event/Value_Judgements_in_Interface_Design5')
|
49
|
-
|
50
44
|
delicious = stub :delicious, :posts_recent => [post1]
|
51
45
|
|
52
46
|
WWW::Delicious.should_receive(:new).and_return delicious
|
@@ -80,12 +74,6 @@ describe Sources::Delicious do
|
|
80
74
|
post1.title = "VIBRAM - FiveFingers"
|
81
75
|
post1.url = URI.parse('http://www.vibramfivefingers.it/')
|
82
76
|
|
83
|
-
# post2 = WWW::Delicious::Post.new
|
84
|
-
# post2.uid = "d0b16f4b7e998a3386052bc95ad0d695"
|
85
|
-
# post2.tags = ["floating", "title", "scrolling", "css", "javascript", "ui"]
|
86
|
-
# post2.title = "Floating Title when Scrolling"
|
87
|
-
# post2.url = URI.parse('http://mesh.scribblelive.com/Event/Value_Judgements_in_Interface_Design5')
|
88
|
-
|
89
77
|
delicious = stub :delicious, :posts_recent => [post1]
|
90
78
|
|
91
79
|
WWW::Delicious.should_receive(:new).and_return delicious
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 10
|
8
|
-
-
|
9
|
-
version: 0.10.
|
8
|
+
- 5
|
9
|
+
version: 0.10.5
|
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-11-
|
17
|
+
date: 2010-11-03 00:00:00 +01:00
|
18
18
|
default_executable: picky
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/picky/signals.rb
|
116
116
|
- lib/picky/solr/schema_generator.rb
|
117
117
|
- lib/picky/sources/base.rb
|
118
|
+
- lib/picky/sources/couch.rb
|
118
119
|
- lib/picky/sources/csv.rb
|
119
120
|
- lib/picky/sources/db.rb
|
120
121
|
- lib/picky/sources/delicious.rb
|
@@ -205,6 +206,7 @@ files:
|
|
205
206
|
- spec/lib/results/live_spec.rb
|
206
207
|
- spec/lib/routing_spec.rb
|
207
208
|
- spec/lib/solr/schema_generator_spec.rb
|
209
|
+
- spec/lib/sources/couch_spec.rb
|
208
210
|
- spec/lib/sources/csv_spec.rb
|
209
211
|
- spec/lib/sources/db_spec.rb
|
210
212
|
- spec/lib/sources/delicious_spec.rb
|
@@ -303,6 +305,7 @@ test_files:
|
|
303
305
|
- spec/lib/results/live_spec.rb
|
304
306
|
- spec/lib/routing_spec.rb
|
305
307
|
- spec/lib/solr/schema_generator_spec.rb
|
308
|
+
- spec/lib/sources/couch_spec.rb
|
306
309
|
- spec/lib/sources/csv_spec.rb
|
307
310
|
- spec/lib/sources/db_spec.rb
|
308
311
|
- spec/lib/sources/delicious_spec.rb
|