From 8001a98a267ea44cc8870f8c3def0f8d09974982 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Thu, 10 Mar 2011 10:42:10 +0000 Subject: [PATCH 1/4] fixed a typo... ffs... --- lib/redistat.rb | 2 +- lib/redistat/label.rb | 2 +- spec/label_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/redistat.rb b/lib/redistat.rb index 8d572e7..00b8e75 100644 --- a/lib/redistat.rb +++ b/lib/redistat.rb @@ -35,7 +35,7 @@ module Redistat KEY_NEXT_ID = ".next_id" KEY_EVENT = ".event:" - KEY_LEBELS = "Redistat.labels:" # used for reverse label hash lookup + KEY_LABELS = "Redistat.labels:" # used for reverse label hash lookup KEY_EVENT_IDS = ".event_ids" LABEL_INDEX = ".label_index:" GROUP_SEPARATOR = "/" diff --git a/lib/redistat/label.rb b/lib/redistat/label.rb index 6ff938d..a6ce099 100644 --- a/lib/redistat/label.rb +++ b/lib/redistat/label.rb @@ -29,7 +29,7 @@ module Redistat end def save - @saved = db.hset(KEY_LEBELS, hash, self.to_s) if @options[:hashed_label] + @saved = db.hset(KEY_LABELS, hash, self.to_s) if @options[:hashed_label] self end diff --git a/spec/label_spec.rb b/spec/label_spec.rb index 8233f05..6e34004 100644 --- a/spec/label_spec.rb +++ b/spec/label_spec.rb @@ -17,12 +17,12 @@ describe Redistat::Label do it "should store a label hash lookup key" do label = Redistat::Label.new(@name, {:hashed_label => true}).save label.saved?.should be_true - db.hget(Redistat::KEY_LEBELS, label.hash).should == @name + db.hget(Redistat::KEY_LABELS, label.hash).should == @name name = "contact_us" label = Redistat::Label.create(name, {:hashed_label => true}) label.saved?.should be_true - db.hget(Redistat::KEY_LEBELS, label.hash).should == name + db.hget(Redistat::KEY_LABELS, label.hash).should == name end describe "Grouping" do From 53aee885bd71e86771259228237ab668ff6a27ea Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Thu, 10 Mar 2011 10:42:24 +0000 Subject: [PATCH 2/4] removed defunct TODO comment --- lib/redistat/key.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/redistat/key.rb b/lib/redistat/key.rb index d829410..5d89572 100644 --- a/lib/redistat/key.rb +++ b/lib/redistat/key.rb @@ -66,7 +66,7 @@ module Redistat end end - def groups # TODO: Is this useless? + def groups @groups ||= @label.groups.map do |label| self.class.new(@scope, label, self.date, @options) end From 57517983f64048795eb56b0276cbbb5a8eaaaf8f Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Thu, 10 Mar 2011 16:26:38 +0000 Subject: [PATCH 3/4] added #parent method to Finder objects --- lib/redistat/finder.rb | 9 +++++++-- spec/finder_spec.rb | 43 +++++++++++++++++++++++++++++------------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/lib/redistat/finder.rb b/lib/redistat/finder.rb index 63c947c..289f0ce 100644 --- a/lib/redistat/finder.rb +++ b/lib/redistat/finder.rb @@ -69,6 +69,10 @@ module Redistat all.each_with_index(&block) end + def parent + @parent ||= self.class.new(options.merge(:label => options[:label].parent)) unless options[:label].nil? + end + def children build_key.children.map { |key| self.class.new(options.merge(:label => key.label.to_s)) @@ -88,8 +92,8 @@ module Redistat end def label(label) - reset! if !options[:label].nil? && options[:label].to_s != label - options[:label] = Label.new(label) + reset! if options.has_key?(:label) && options[:label].to_s != label.to_s + options[:label] = (!label.nil?) ? Label.new(label) : nil self end @@ -181,6 +185,7 @@ module Redistat def reset! @result = nil + @parent = nil end def valid_options? diff --git a/spec/finder_spec.rb b/spec/finder_spec.rb index 0d8df60..bf60a29 100644 --- a/spec/finder_spec.rb +++ b/spec/finder_spec.rb @@ -91,19 +91,36 @@ describe Redistat::Finder do lambda { Redistat::Finder.find(:from => 3.hours.ago) }.should raise_error(Redistat::InvalidOptions) end - it "should find children" do - Redistat::Key.new("PageViews", "message/public/die").update_index - Redistat::Key.new("PageViews", "message/public/live").update_index - Redistat::Key.new("PageViews", "message/public/fester").update_index - members = db.smembers("#{@scope}#{Redistat::LABEL_INDEX}message/public") # checking 'message/public' - options = {:scope => "PageViews", :label => "message/public", :from => @two_hours_ago, :till => @one_hour_ago, :depth => :hour, :interval => :hour} - finder = Redistat::Finder.new(options) - finder.children.first.should be_a(Redistat::Finder) - subs = finder.children.map { |f| f.options[:label].me } - subs.should have(3).items - subs.should include('die') - subs.should include('live') - subs.should include('fester') + describe "Grouping" do + before(:each) do + @options = {:scope => "PageViews", :label => "message/public", :from => @two_hours_ago, :till => @one_hour_ago, :depth => :hour, :interval => :hour} + @finder = Redistat::Finder.new(@options) + end + + it "should return parent finder" do + @finder.instance_variable_get("@parent").should be_nil + @finder.parent.should be_a(Redistat::Finder) + @finder.instance_variable_get("@parent").should_not be_nil + @finder.parent.options[:label].to_s.should == 'message' + @finder.label('message') + @finder.instance_variable_get("@parent").should be_nil + @finder.parent.should_not be_nil + @finder.parent.options[:label].should be_nil + @finder.parent.parent.should be_nil + end + + it "should find children" do + Redistat::Key.new("PageViews", "message/public/die").update_index + Redistat::Key.new("PageViews", "message/public/live").update_index + Redistat::Key.new("PageViews", "message/public/fester").update_index + members = db.smembers("#{@scope}#{Redistat::LABEL_INDEX}message/public") # checking 'message/public' + @finder.children.first.should be_a(Redistat::Finder) + subs = @finder.children.map { |f| f.options[:label].me } + subs.should have(3).items + subs.should include('die') + subs.should include('live') + subs.should include('fester') + end end describe "Lazy-Loading" do From f2c026c1eb6e90a0aeb931745bab70afb893882a Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Thu, 10 Mar 2011 16:27:24 +0000 Subject: [PATCH 4/4] started release v0.2.1 --- lib/redistat/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/redistat/version.rb b/lib/redistat/version.rb index 113e8e4..b2350f8 100644 --- a/lib/redistat/version.rb +++ b/lib/redistat/version.rb @@ -1,3 +1,3 @@ module Redistat - VERSION = "0.2.0" + VERSION = "0.2.1" end