barnyard_harvester 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- redis_args = @redis_settings
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
- redis_args[:db] = args[:crop_number]
26
+ @redis_settings[:db] = args[:crop_number]
25
27
 
26
28
  # Connect to Redis
27
- @redis = Redis.new(redis_args)
29
+ @redis = Redis.new(@redis_settings)
28
30
 
29
31
  end
30
32
 
@@ -1,3 +1,3 @@
1
1
  module BarnyardHarvester
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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 => 1, :redis_settings => redis_settings, :logger => my_logger)
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
- def flush
39
+ def flush
37
40
 
38
- r = Redis.new(:db => 1)
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
- before(:each) do
48
+ end
47
49
 
48
- flush
50
+ before(:each) do
49
51
 
50
- @crop_number = 1
52
+ flush
51
53
 
52
- file = "spec/fixtures/data-init.yml"
54
+ @crop_number = 1
53
55
 
54
- data = YAML::load_file file
56
+ file = "spec/fixtures/data-init.yml"
55
57
 
56
- h = load_and_process_file(file, :redis)
58
+ data = YAML::load_file file
57
59
 
58
- h.add_count.should eq(data.count)
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
- end
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
- it "test initial load of records" do
68
+ end
67
69
 
68
- data = YAML::load_file "spec/fixtures/data-init.yml"
70
+ it "test initial load of records" do
69
71
 
70
- redis = Redis.new(:db => 1)
72
+ data = YAML::load_file "spec/fixtures/data-init.yml"
71
73
 
72
- data.each do |primary_key, value|
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
- it "test add one record" do
80
+ end
81
+
82
+ it "test add one record" do
79
83
 
80
- file = "spec/fixtures/data-add.yml"
81
- data = YAML::load_file file
84
+ file = "spec/fixtures/data-add.yml"
85
+ data = YAML::load_file file
82
86
 
83
- h = load_and_process_file(file, :redis)
87
+ h = load_and_process_file(file, :redis)
84
88
 
85
- h.add_count.should eq(1)
86
- h.delete_count.should eq(0)
87
- h.change_count.should eq(0)
88
- h.source_count.should eq(data.count)
89
- h.cache_count.should eq(data.count)
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
- end
95
+ end
92
96
 
93
- it "test change one record" do
97
+ it "test change one record" do
94
98
 
95
- file = "spec/fixtures/data-change.yml"
99
+ file = "spec/fixtures/data-change.yml"
96
100
 
97
- data = YAML::load_file file
101
+ data = YAML::load_file file
98
102
 
99
- h = load_and_process_file(file, :redis)
103
+ h = load_and_process_file(file, :redis)
100
104
 
101
- h.add_count.should eq(0)
102
- h.delete_count.should eq(0)
103
- h.change_count.should eq(1)
104
- h.source_count.should eq(data.count)
105
- h.cache_count.should eq(data.count)
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
- end
111
+ end
108
112
 
109
- it "test delete one record" do
113
+ it "test delete one record" do
110
114
 
111
- file = "spec/fixtures/data-delete.yml"
115
+ file = "spec/fixtures/data-delete.yml"
112
116
 
113
- data = YAML::load_file file
117
+ data = YAML::load_file file
114
118
 
115
- h = load_and_process_file(file, :redis)
119
+ h = load_and_process_file(file, :redis)
116
120
 
117
121
 
118
- h.add_count.should eq(0)
119
- h.delete_count.should eq(1)
120
- h.change_count.should eq(0)
121
- h.source_count.should eq(data.count)
122
- h.cache_count.should eq(data.count + 1)
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
- end
128
+ end
125
129
 
126
- it "test delete all records and add one" do
130
+ it "test delete all records and add one" do
127
131
 
128
- init_file = "spec/fixtures/data-init.yml"
129
- init_data = YAML::load_file init_file
132
+ init_file = "spec/fixtures/data-init.yml"
133
+ init_data = YAML::load_file init_file
130
134
 
131
- file = "spec/fixtures/data-delete-all-records-add-one.yml"
132
- #data = YAML::load_file file
135
+ file = "spec/fixtures/data-delete-all-records-add-one.yml"
136
+ #data = YAML::load_file file
133
137
 
134
- h = load_and_process_file(file, :redis)
138
+ h = load_and_process_file(file, :redis)
135
139
 
136
- h.add_count.should eq(1)
137
- h.delete_count.should eq(5)
138
- h.change_count.should eq(0)
139
- h.source_count.should eq(1)
140
- h.cache_count.should eq(init_data.count + 1)
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
- end
146
+ end
143
147
 
144
148
 
145
- after(:each) do
146
- end
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.1
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-10 00:00:00.000000000 Z
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: &70309177353080 !ruby/object:Gem::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: *70309177353080
24
+ version_requirements: *70185021713620
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: resque
27
- requirement: &70309177352620 !ruby/object:Gem::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: *70309177352620
35
+ version_requirements: *70185021729120
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: crack
38
- requirement: &70309177352180 !ruby/object:Gem::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: *70309177352180
46
+ version_requirements: *70185021728360
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: json
49
- requirement: &70309177351760 !ruby/object:Gem::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: *70309177351760
57
+ version_requirements: *70185021727680
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: uuid
60
- requirement: &70309177351320 !ruby/object:Gem::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: *70309177351320
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.15
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.