barnyard_harvester 0.0.1 → 0.0.2
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/barnyard_harvester/redis.rb +5 -3
- data/lib/barnyard_harvester/version.rb +1 -1
- data/lib/barnyard_harvester.rb +0 -11
- data/spec/redis_spec.rb +78 -74
- metadata +13 -13
@@ -18,13 +18,15 @@ module BarnyardHarvester
|
|
18
18
|
@debug = args.fetch(:debug) { false }
|
19
19
|
@log = args.fetch(:logger) { Logger.new(STDOUT) }
|
20
20
|
|
21
|
-
|
21
|
+
@redis_settings.delete(:db)
|
22
|
+
|
23
|
+
Resque.redis = Redis.new(@redis_settings)
|
22
24
|
|
23
25
|
# This sets the database number for redis to store the cached data
|
24
|
-
|
26
|
+
@redis_settings[:db] = args[:crop_number]
|
25
27
|
|
26
28
|
# Connect to Redis
|
27
|
-
@redis = Redis.new(
|
29
|
+
@redis = Redis.new(@redis_settings)
|
28
30
|
|
29
31
|
end
|
30
32
|
|
data/lib/barnyard_harvester.rb
CHANGED
@@ -8,17 +8,6 @@ module BarnyardHarvester
|
|
8
8
|
CHANGE = "change"
|
9
9
|
DELETE = "delete"
|
10
10
|
|
11
|
-
# Available Options:
|
12
|
-
#
|
13
|
-
# :crop_number (required)
|
14
|
-
# :debug true/1
|
15
|
-
# :resque_enqueue true/1 (Goes to Farmer queue)
|
16
|
-
#
|
17
|
-
# :logger_call_back (calls this function with a load of params)
|
18
|
-
# :data_call_back (I totally forgot what this was for)
|
19
|
-
# :backend (default is :redis, available are: :hash, :mongodb)
|
20
|
-
#
|
21
|
-
|
22
11
|
DEFAULT_REDIS_SETTINGS = {:host => "localhost", :port => 6379}
|
23
12
|
|
24
13
|
class Sync
|
data/spec/redis_spec.rb
CHANGED
@@ -7,6 +7,14 @@ require "json"
|
|
7
7
|
|
8
8
|
# TODO.. Move the flush to the backend object, not here!!!!!!!!!
|
9
9
|
|
10
|
+
CROP_NUMBER = 1
|
11
|
+
|
12
|
+
REDIS_SETTINGS = {
|
13
|
+
:host => "localhost",
|
14
|
+
:port => 6379,
|
15
|
+
:db => CROP_NUMBER
|
16
|
+
}
|
17
|
+
|
10
18
|
describe BarnyardHarvester do
|
11
19
|
|
12
20
|
|
@@ -14,15 +22,10 @@ describe BarnyardHarvester do
|
|
14
22
|
|
15
23
|
data = YAML::load_file file
|
16
24
|
|
17
|
-
redis_settings = {
|
18
|
-
:host => "localhost",
|
19
|
-
:port => 6379,
|
20
|
-
}
|
21
|
-
|
22
25
|
my_logger = Logger.new(STDOUT)
|
23
26
|
my_logger.level = Logger::INFO
|
24
27
|
|
25
|
-
h = BarnyardHarvester::Sync.new(:backend => backend, :debug => false, :crop_number =>
|
28
|
+
h = BarnyardHarvester::Sync.new(:backend => backend, :debug => false, :crop_number => CROP_NUMBER, :redis_settings => REDIS_SETTINGS, :logger => my_logger)
|
26
29
|
|
27
30
|
h.run do
|
28
31
|
data.each do |primary_key, value|
|
@@ -33,117 +36,118 @@ describe BarnyardHarvester do
|
|
33
36
|
h
|
34
37
|
end
|
35
38
|
|
36
|
-
|
39
|
+
def flush
|
37
40
|
|
38
|
-
|
39
|
-
|
40
|
-
r.keys.each do |k|
|
41
|
-
r.del k
|
42
|
-
end
|
41
|
+
r = Redis.new(REDIS_SETTINGS)
|
43
42
|
|
43
|
+
r.keys.each do |k|
|
44
|
+
r.del k
|
45
|
+
#puts "deleted #{k}"
|
44
46
|
end
|
45
47
|
|
46
|
-
|
48
|
+
end
|
47
49
|
|
48
|
-
|
50
|
+
before(:each) do
|
49
51
|
|
50
|
-
|
52
|
+
flush
|
51
53
|
|
52
|
-
|
54
|
+
@crop_number = 1
|
53
55
|
|
54
|
-
|
56
|
+
file = "spec/fixtures/data-init.yml"
|
55
57
|
|
56
|
-
|
58
|
+
data = YAML::load_file file
|
57
59
|
|
58
|
-
|
59
|
-
h.delete_count.should eq(0)
|
60
|
-
h.change_count.should eq(0)
|
61
|
-
h.source_count.should eq(data.count)
|
62
|
-
h.cache_count.should eq(data.count)
|
60
|
+
h = load_and_process_file(file, :redis)
|
63
61
|
|
64
|
-
|
62
|
+
h.add_count.should eq(data.count)
|
63
|
+
h.delete_count.should eq(0)
|
64
|
+
h.change_count.should eq(0)
|
65
|
+
h.source_count.should eq(data.count)
|
66
|
+
h.cache_count.should eq(data.count)
|
65
67
|
|
66
|
-
|
68
|
+
end
|
67
69
|
|
68
|
-
|
70
|
+
it "test initial load of records" do
|
69
71
|
|
70
|
-
|
72
|
+
data = YAML::load_file "spec/fixtures/data-init.yml"
|
71
73
|
|
72
|
-
|
73
|
-
value.to_json.should eq(redis.get(primary_key))
|
74
|
-
end
|
74
|
+
redis = Redis.new(REDIS_SETTINGS)
|
75
75
|
|
76
|
+
data.each do |primary_key, value|
|
77
|
+
value.to_json.should eq(redis.get(primary_key))
|
76
78
|
end
|
77
79
|
|
78
|
-
|
80
|
+
end
|
81
|
+
|
82
|
+
it "test add one record" do
|
79
83
|
|
80
|
-
|
81
|
-
|
84
|
+
file = "spec/fixtures/data-add.yml"
|
85
|
+
data = YAML::load_file file
|
82
86
|
|
83
|
-
|
87
|
+
h = load_and_process_file(file, :redis)
|
84
88
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
89
|
+
h.add_count.should eq(1)
|
90
|
+
h.delete_count.should eq(0)
|
91
|
+
h.change_count.should eq(0)
|
92
|
+
h.source_count.should eq(data.count)
|
93
|
+
h.cache_count.should eq(data.count)
|
90
94
|
|
91
|
-
|
95
|
+
end
|
92
96
|
|
93
|
-
|
97
|
+
it "test change one record" do
|
94
98
|
|
95
|
-
|
99
|
+
file = "spec/fixtures/data-change.yml"
|
96
100
|
|
97
|
-
|
101
|
+
data = YAML::load_file file
|
98
102
|
|
99
|
-
|
103
|
+
h = load_and_process_file(file, :redis)
|
100
104
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
105
|
+
h.add_count.should eq(0)
|
106
|
+
h.delete_count.should eq(0)
|
107
|
+
h.change_count.should eq(1)
|
108
|
+
h.source_count.should eq(data.count)
|
109
|
+
h.cache_count.should eq(data.count)
|
106
110
|
|
107
|
-
|
111
|
+
end
|
108
112
|
|
109
|
-
|
113
|
+
it "test delete one record" do
|
110
114
|
|
111
|
-
|
115
|
+
file = "spec/fixtures/data-delete.yml"
|
112
116
|
|
113
|
-
|
117
|
+
data = YAML::load_file file
|
114
118
|
|
115
|
-
|
119
|
+
h = load_and_process_file(file, :redis)
|
116
120
|
|
117
121
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
122
|
+
h.add_count.should eq(0)
|
123
|
+
h.delete_count.should eq(1)
|
124
|
+
h.change_count.should eq(0)
|
125
|
+
h.source_count.should eq(data.count)
|
126
|
+
h.cache_count.should eq(data.count + 1)
|
123
127
|
|
124
|
-
|
128
|
+
end
|
125
129
|
|
126
|
-
|
130
|
+
it "test delete all records and add one" do
|
127
131
|
|
128
|
-
|
129
|
-
|
132
|
+
init_file = "spec/fixtures/data-init.yml"
|
133
|
+
init_data = YAML::load_file init_file
|
130
134
|
|
131
|
-
|
132
|
-
|
135
|
+
file = "spec/fixtures/data-delete-all-records-add-one.yml"
|
136
|
+
#data = YAML::load_file file
|
133
137
|
|
134
|
-
|
138
|
+
h = load_and_process_file(file, :redis)
|
135
139
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
140
|
+
h.add_count.should eq(1)
|
141
|
+
h.delete_count.should eq(5)
|
142
|
+
h.change_count.should eq(0)
|
143
|
+
h.source_count.should eq(1)
|
144
|
+
h.cache_count.should eq(init_data.count + 1)
|
141
145
|
|
142
|
-
|
146
|
+
end
|
143
147
|
|
144
148
|
|
145
|
-
|
146
|
-
|
149
|
+
after(:each) do
|
150
|
+
end
|
147
151
|
|
148
152
|
|
149
153
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barnyard_harvester
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70185021713620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70185021713620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: resque
|
27
|
-
requirement: &
|
27
|
+
requirement: &70185021729120 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70185021729120
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: crack
|
38
|
-
requirement: &
|
38
|
+
requirement: &70185021728360 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70185021728360
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: json
|
49
|
-
requirement: &
|
49
|
+
requirement: &70185021727680 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70185021727680
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: uuid
|
60
|
-
requirement: &
|
60
|
+
requirement: &70185021727000 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :runtime
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70185021727000
|
69
69
|
description: Performs harvests on data sources and detects adds, changes and deletes.
|
70
70
|
email:
|
71
71
|
- supercoder@gmail.com
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project: barnyard_harvester
|
121
|
-
rubygems_version: 1.8.
|
121
|
+
rubygems_version: 1.8.11
|
122
122
|
signing_key:
|
123
123
|
specification_version: 3
|
124
124
|
summary: Please check the README.md for more information.
|