trifle 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,8 @@ GIT
9
9
  PATH
10
10
  remote: .
11
11
  specs:
12
- trifle (0.0.5)
12
+ trifle (0.0.7)
13
+ redis
13
14
 
14
15
  GEM
15
16
  remote: http://rubygems.org/
@@ -27,7 +28,6 @@ GEM
27
28
  rspec-expectations (2.10.0)
28
29
  diff-lcs (~> 1.1.3)
29
30
  rspec-mocks (2.10.1)
30
- rujitsu (0.3.3)
31
31
 
32
32
  PLATFORMS
33
33
  ruby
@@ -36,5 +36,4 @@ DEPENDENCIES
36
36
  active_support
37
37
  fakeredis!
38
38
  rspec
39
- rujitsu
40
39
  trifle!
data/README.md CHANGED
@@ -65,6 +65,7 @@ trifle.find "192.168.1.1"
65
65
 
66
66
  ## Release notes
67
67
 
68
+ * **0.0.7** Loading now happens into separate key, making loading possible without downtime
68
69
  * **0.0.6** Added a fix for invalid IPs
69
70
  * **0.0.5** Fixed bug when finding IPs at the edge of the data set
70
71
  * **0.0.4** Changed binary syntax
@@ -17,6 +17,16 @@ class Trifle
17
17
  end
18
18
  end
19
19
 
20
+ def tmp_key
21
+ "#{key}:tmp"
22
+ end
23
+
24
+ def clear
25
+ redis.del key
26
+ end
27
+
28
+ protected
29
+
20
30
  def load_files filenames
21
31
  raise ArgumentError.new("filenames must be an array of strings") unless filenames.is_a?(Array) && !filenames.map{|element| element.is_a?(String)}.include?(false)
22
32
 
@@ -33,11 +43,12 @@ class Trifle
33
43
  clear
34
44
  sort(data)
35
45
  data.each {|row| append(row) }
46
+ move
36
47
  end
37
48
 
38
49
  def append row
39
50
  entry = row.values_at(2,3,4,5).join(":")
40
- redis.rpush key, entry
51
+ redis.rpush tmp_key, entry
41
52
  end
42
53
 
43
54
  def sort data
@@ -60,8 +71,8 @@ class Trifle
60
71
  field.is_a?(Numeric) || field =~ /^\d+$/
61
72
  end
62
73
 
63
- def clear
64
- redis.del key
74
+ def move
75
+ redis.rename tmp_key, key
65
76
  end
66
77
  end
67
78
  end
@@ -1,3 +1,3 @@
1
1
  class Trifle
2
- VERSION = "0.0.6" unless defined? Trifle::VERSION
2
+ VERSION = "0.0.7" unless defined? Trifle::VERSION
3
3
  end
@@ -1,3 +1,2 @@
1
1
  require "trifle"
2
- require "rujitsu"
3
2
  require "fakeredis/rspec"
@@ -63,21 +63,21 @@ describe Trifle::Loader do
63
63
  end
64
64
 
65
65
  it "should read the files" do
66
- @loader.load_files @filenames
66
+ @loader.send(:load_files, @filenames)
67
67
  @loader.redis.llen(@loader.key).should be == 4
68
68
  end
69
69
  end
70
70
 
71
71
  context "when given anything but an array of strings" do
72
72
  it "should raise an error" do
73
- -> { @loader.load_files "" }.should raise_error(ArgumentError)
74
- -> { @loader.load_files [:foo] }.should raise_error(ArgumentError)
73
+ -> { @loader.send(:load_files, "") }.should raise_error(ArgumentError)
74
+ -> { @loader.send(:load_files, [:foo]) }.should raise_error(ArgumentError)
75
75
  end
76
76
  end
77
77
 
78
78
  context "when given a filename for a file that's missing" do
79
79
  it "should raise an error" do
80
- -> { @loader.load_files ["foobar.csv"] }.should raise_error(/No such file or directory - foobar.csv/)
80
+ -> { @loader.send(:load_files, ["foobar.csv"]) }.should raise_error(/No such file or directory - foobar.csv/)
81
81
  end
82
82
  end
83
83
  end
@@ -87,41 +87,48 @@ describe Trifle::Loader do
87
87
  context "when given valid data" do
88
88
  it "should clear out existing data" do
89
89
  @loader.should_receive(:clear)
90
- @loader.load_data @valid_data
90
+ @loader.send(:load_data, @valid_data)
91
91
  end
92
92
 
93
93
  it "should validate the data" do
94
94
  @loader.should_receive(:valid?).and_return(true)
95
- @loader.load_data @valid_data
95
+ @loader.send(:load_data, @valid_data)
96
96
  end
97
97
 
98
98
  it "should load it in redis" do
99
- @loader.load_data @valid_data
99
+ @loader.send(:load_data, @valid_data)
100
100
  @loader.redis.llen(@loader.key).should be == 2
101
101
  end
102
+
103
+ it "should load via a tmp key to ensure no downtime" do
104
+ @loader.should_receive(:move)
105
+ @loader.send(:load_data, @valid_data)
106
+ @loader.redis.get(@loader.key).should be_nil
107
+ @loader.redis.llen(@loader.tmp_key).should be == 2
108
+ end
102
109
  end
103
110
 
104
111
  context "when given invalid data" do
105
112
  it "should raise an error" do
106
113
  @loader.should_receive(:valid?).and_return(false)
107
- -> { @loader.load_data @valid_data }.should raise_error(ArgumentError)
114
+ -> { @loader.send(:load_data, @valid_data) }.should raise_error(ArgumentError)
108
115
  end
109
116
  end
110
117
 
111
118
  context "when given anything but an array" do
112
119
  it "should raise an error" do
113
- -> { @loader.load_data :rubbish }.should raise_error(ArgumentError)
120
+ -> { @loader.send(:load_data, :rubbish) }.should raise_error(ArgumentError)
114
121
  end
115
122
  end
116
123
  end
117
124
 
118
125
  describe "#parse" do
119
126
  it "should parse valid csv data" do
120
- @loader.parse(@csv).should be == @valid_data
127
+ @loader.send(:parse, @csv).should be == @valid_data
121
128
  end
122
129
 
123
130
  it "should raise an error for invalid csv data" do
124
- -> { @loader.parse('"foo",","#') }.should raise_error(CSV::MalformedCSVError)
131
+ -> { @loader.send(:parse, '"foo",","#') }.should raise_error(CSV::MalformedCSVError)
125
132
  end
126
133
 
127
134
  it "should handle ipv6 data" do
@@ -129,39 +136,39 @@ describe Trifle::Loader do
129
136
  "2c0f:ffe8::", "2c0f:ffe8:ffff:ffff:ffff:ffff:ffff:ffff", "58569106662796955307479896348547874816", "58569106742025117821744233942091825151", "NG", "Nigeria"
130
137
  "2c0f:fff0::", "2c0f:fff0:ffff:ffff:ffff:ffff:ffff:ffff", "58569107296622255421594597096899477504", "58569107375850417935858934690443427839", "NG", "Nigeria"
131
138
  CSV
132
- -> { @loader.parse(@ipv6csv) }.should_not raise_error
139
+ -> { @loader.send(:parse, @ipv6csv) }.should_not raise_error
133
140
  end
134
141
  end
135
142
 
136
143
  describe "#sort" do
137
144
  it "should sort the data" do
138
- @loader.sort(@valid_data.reverse).should be == @valid_data
145
+ @loader.send(:sort, @valid_data.reverse).should be == @valid_data
139
146
  end
140
147
  end
141
148
 
142
149
 
143
150
  describe "#valid?" do
144
151
  it "should mark valid data as such" do
145
- @loader.valid?(@valid_data).should be_true
152
+ @loader.send(:valid?, @valid_data).should be_true
146
153
  end
147
154
 
148
155
  it "should mark invalid data as such" do
149
156
  invalid_data = []
150
- @loader.valid?(invalid_data).should be_false
157
+ @loader.send(:valid?, invalid_data).should be_false
151
158
  invalid_data = [
152
159
  ["223.255.254.0","223.255.254.255","not_a_number","3758096127","SG","Singapore"]
153
160
  ]
154
- @loader.valid?(invalid_data).should be_false
161
+ @loader.send(:valid?, invalid_data).should be_false
155
162
  invalid_data = [
156
163
  ["223.255.254.0","223.255.254.255","3758095872","not_a_number","SG","Singapore"]
157
164
  ]
158
- @loader.valid?(invalid_data).should be_false
165
+ @loader.send(:valid?, invalid_data).should be_false
159
166
  end
160
167
  end
161
168
 
162
169
  describe "#clear" do
163
170
  it "should clear existing data" do
164
- @loader.load_data @valid_data
171
+ @loader.send(:load_data, @valid_data)
165
172
  @loader.clear
166
173
  @loader.redis.llen(@loader.key).should be == 0
167
174
  end
@@ -19,7 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_development_dependency 'rspec'
22
- s.add_development_dependency 'rujitsu'
23
22
  s.add_development_dependency 'active_support'
24
23
  s.add_development_dependency "fakeredis", "~> 0.3.0"
24
+
25
+ s.add_dependency 'redis'
25
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trifle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
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-06-21 00:00:00.000000000 Z
12
+ date: 2012-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70348294670440 !ruby/object:Gem::Requirement
16
+ requirement: &70133403697660 !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: *70348294670440
24
+ version_requirements: *70133403697660
25
25
  - !ruby/object:Gem::Dependency
26
- name: rujitsu
27
- requirement: &70348294688940 !ruby/object:Gem::Requirement
26
+ name: active_support
27
+ requirement: &70133403697060 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,29 +32,29 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70348294688940
35
+ version_requirements: *70133403697060
36
36
  - !ruby/object:Gem::Dependency
37
- name: active_support
38
- requirement: &70348294688500 !ruby/object:Gem::Requirement
37
+ name: fakeredis
38
+ requirement: &70133403696340 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
- - - ! '>='
41
+ - - ~>
42
42
  - !ruby/object:Gem::Version
43
- version: '0'
43
+ version: 0.3.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70348294688500
46
+ version_requirements: *70133403696340
47
47
  - !ruby/object:Gem::Dependency
48
- name: fakeredis
49
- requirement: &70348294688000 !ruby/object:Gem::Requirement
48
+ name: redis
49
+ requirement: &70133403695580 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
- - - ~>
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
- version: 0.3.0
55
- type: :development
54
+ version: '0'
55
+ type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70348294688000
57
+ version_requirements: *70133403695580
58
58
  description: Stores the GeoIP databases in Redis and gives it a simple way to lookup
59
59
  IPs and map them to countries
60
60
  email: