redistat 0.2.0 → 0.2.1

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/redistat.rb CHANGED
@@ -35,7 +35,7 @@ module Redistat
35
35
 
36
36
  KEY_NEXT_ID = ".next_id"
37
37
  KEY_EVENT = ".event:"
38
- KEY_LEBELS = "Redistat.labels:" # used for reverse label hash lookup
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 = "/"
@@ -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 !options[:label].nil? && options[:label].to_s != label
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
@@ -66,7 +66,7 @@ module Redistat
66
66
  end
67
67
  end
68
68
 
69
- def groups # TODO: Is this useless?
69
+ def groups
70
70
  @groups ||= @label.groups.map do |label|
71
71
  self.class.new(@scope, label, self.date, @options)
72
72
  end
@@ -29,7 +29,7 @@ module Redistat
29
29
  end
30
30
 
31
31
  def save
32
- @saved = db.hset(KEY_LEBELS, hash, self.to_s) if @options[:hashed_label]
32
+ @saved = db.hset(KEY_LABELS, hash, self.to_s) if @options[:hashed_label]
33
33
  self
34
34
  end
35
35
 
@@ -1,3 +1,3 @@
1
1
  module Redistat
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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
- it "should find children" do
95
- Redistat::Key.new("PageViews", "message/public/die").update_index
96
- Redistat::Key.new("PageViews", "message/public/live").update_index
97
- Redistat::Key.new("PageViews", "message/public/fester").update_index
98
- members = db.smembers("#{@scope}#{Redistat::LABEL_INDEX}message/public") # checking 'message/public'
99
- options = {:scope => "PageViews", :label => "message/public", :from => @two_hours_ago, :till => @one_hour_ago, :depth => :hour, :interval => :hour}
100
- finder = Redistat::Finder.new(options)
101
- finder.children.first.should be_a(Redistat::Finder)
102
- subs = finder.children.map { |f| f.options[:label].me }
103
- subs.should have(3).items
104
- subs.should include('die')
105
- subs.should include('live')
106
- subs.should include('fester')
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::KEY_LEBELS, label.hash).should == @name
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::KEY_LEBELS, label.hash).should == name
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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jim Myhrberg