redistat 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/redistat.rb +1 -1
- data/lib/redistat/finder.rb +7 -2
- data/lib/redistat/key.rb +1 -1
- data/lib/redistat/label.rb +1 -1
- data/lib/redistat/version.rb +1 -1
- data/spec/finder_spec.rb +30 -13
- data/spec/label_spec.rb +2 -2
- metadata +3 -3
data/lib/redistat.rb
CHANGED
@@ -35,7 +35,7 @@ module Redistat
|
|
35
35
|
|
36
36
|
KEY_NEXT_ID = ".next_id"
|
37
37
|
KEY_EVENT = ".event:"
|
38
|
-
|
38
|
+
KEY_LABELS = "Redistat.labels:" # used for reverse label hash lookup
|
39
39
|
KEY_EVENT_IDS = ".event_ids"
|
40
40
|
LABEL_INDEX = ".label_index:"
|
41
41
|
GROUP_SEPARATOR = "/"
|
data/lib/redistat/finder.rb
CHANGED
@@ -69,6 +69,10 @@ module Redistat
|
|
69
69
|
all.each_with_index(&block)
|
70
70
|
end
|
71
71
|
|
72
|
+
def parent
|
73
|
+
@parent ||= self.class.new(options.merge(:label => options[:label].parent)) unless options[:label].nil?
|
74
|
+
end
|
75
|
+
|
72
76
|
def children
|
73
77
|
build_key.children.map { |key|
|
74
78
|
self.class.new(options.merge(:label => key.label.to_s))
|
@@ -88,8 +92,8 @@ module Redistat
|
|
88
92
|
end
|
89
93
|
|
90
94
|
def label(label)
|
91
|
-
reset! if
|
92
|
-
options[:label] = Label.new(label)
|
95
|
+
reset! if options.has_key?(:label) && options[:label].to_s != label.to_s
|
96
|
+
options[:label] = (!label.nil?) ? Label.new(label) : nil
|
93
97
|
self
|
94
98
|
end
|
95
99
|
|
@@ -181,6 +185,7 @@ module Redistat
|
|
181
185
|
|
182
186
|
def reset!
|
183
187
|
@result = nil
|
188
|
+
@parent = nil
|
184
189
|
end
|
185
190
|
|
186
191
|
def valid_options?
|
data/lib/redistat/key.rb
CHANGED
data/lib/redistat/label.rb
CHANGED
data/lib/redistat/version.rb
CHANGED
data/spec/finder_spec.rb
CHANGED
@@ -91,19 +91,36 @@ describe Redistat::Finder do
|
|
91
91
|
lambda { Redistat::Finder.find(:from => 3.hours.ago) }.should raise_error(Redistat::InvalidOptions)
|
92
92
|
end
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
finder
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
94
|
+
describe "Grouping" do
|
95
|
+
before(:each) do
|
96
|
+
@options = {:scope => "PageViews", :label => "message/public", :from => @two_hours_ago, :till => @one_hour_ago, :depth => :hour, :interval => :hour}
|
97
|
+
@finder = Redistat::Finder.new(@options)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should return parent finder" do
|
101
|
+
@finder.instance_variable_get("@parent").should be_nil
|
102
|
+
@finder.parent.should be_a(Redistat::Finder)
|
103
|
+
@finder.instance_variable_get("@parent").should_not be_nil
|
104
|
+
@finder.parent.options[:label].to_s.should == 'message'
|
105
|
+
@finder.label('message')
|
106
|
+
@finder.instance_variable_get("@parent").should be_nil
|
107
|
+
@finder.parent.should_not be_nil
|
108
|
+
@finder.parent.options[:label].should be_nil
|
109
|
+
@finder.parent.parent.should be_nil
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should find children" do
|
113
|
+
Redistat::Key.new("PageViews", "message/public/die").update_index
|
114
|
+
Redistat::Key.new("PageViews", "message/public/live").update_index
|
115
|
+
Redistat::Key.new("PageViews", "message/public/fester").update_index
|
116
|
+
members = db.smembers("#{@scope}#{Redistat::LABEL_INDEX}message/public") # checking 'message/public'
|
117
|
+
@finder.children.first.should be_a(Redistat::Finder)
|
118
|
+
subs = @finder.children.map { |f| f.options[:label].me }
|
119
|
+
subs.should have(3).items
|
120
|
+
subs.should include('die')
|
121
|
+
subs.should include('live')
|
122
|
+
subs.should include('fester')
|
123
|
+
end
|
107
124
|
end
|
108
125
|
|
109
126
|
describe "Lazy-Loading" do
|
data/spec/label_spec.rb
CHANGED
@@ -17,12 +17,12 @@ describe Redistat::Label do
|
|
17
17
|
it "should store a label hash lookup key" do
|
18
18
|
label = Redistat::Label.new(@name, {:hashed_label => true}).save
|
19
19
|
label.saved?.should be_true
|
20
|
-
db.hget(Redistat::
|
20
|
+
db.hget(Redistat::KEY_LABELS, label.hash).should == @name
|
21
21
|
|
22
22
|
name = "contact_us"
|
23
23
|
label = Redistat::Label.create(name, {:hashed_label => true})
|
24
24
|
label.saved?.should be_true
|
25
|
-
db.hget(Redistat::
|
25
|
+
db.hget(Redistat::KEY_LABELS, label.hash).should == name
|
26
26
|
end
|
27
27
|
|
28
28
|
describe "Grouping" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redistat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jim Myhrberg
|