6 Commits

Author SHA1 Message Date
331bf81e3a Merge branch 'release/v0.2.1' 2011-03-10 16:31:34 +00:00
f2c026c1eb started release v0.2.1 2011-03-10 16:27:24 +00:00
57517983f6 added #parent method to Finder objects 2011-03-10 16:26:38 +00:00
53aee885bd removed defunct TODO comment 2011-03-10 10:42:24 +00:00
8001a98a26 fixed a typo... ffs... 2011-03-10 10:42:10 +00:00
34331a655e Merge branch 'release/v0.2.0' into dev 2011-03-10 00:49:22 +00:00
7 changed files with 43 additions and 21 deletions

View File

@@ -35,7 +35,7 @@ module Redistat
KEY_NEXT_ID = ".next_id" KEY_NEXT_ID = ".next_id"
KEY_EVENT = ".event:" 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" KEY_EVENT_IDS = ".event_ids"
LABEL_INDEX = ".label_index:" LABEL_INDEX = ".label_index:"
GROUP_SEPARATOR = "/" GROUP_SEPARATOR = "/"

View File

@@ -69,6 +69,10 @@ module Redistat
all.each_with_index(&block) all.each_with_index(&block)
end end
def parent
@parent ||= self.class.new(options.merge(:label => options[:label].parent)) unless options[:label].nil?
end
def children def children
build_key.children.map { |key| build_key.children.map { |key|
self.class.new(options.merge(:label => key.label.to_s)) self.class.new(options.merge(:label => key.label.to_s))
@@ -88,8 +92,8 @@ module Redistat
end end
def label(label) def label(label)
reset! if !options[:label].nil? && options[:label].to_s != label reset! if options.has_key?(:label) && options[:label].to_s != label.to_s
options[:label] = Label.new(label) options[:label] = (!label.nil?) ? Label.new(label) : nil
self self
end end
@@ -181,6 +185,7 @@ module Redistat
def reset! def reset!
@result = nil @result = nil
@parent = nil
end end
def valid_options? def valid_options?

View File

@@ -66,7 +66,7 @@ module Redistat
end end
end end
def groups # TODO: Is this useless? def groups
@groups ||= @label.groups.map do |label| @groups ||= @label.groups.map do |label|
self.class.new(@scope, label, self.date, @options) self.class.new(@scope, label, self.date, @options)
end end

View File

@@ -29,7 +29,7 @@ module Redistat
end end
def save 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 self
end end

View File

@@ -1,3 +1,3 @@
module Redistat module Redistat
VERSION = "0.2.0" VERSION = "0.2.1"
end end

View File

@@ -91,19 +91,36 @@ describe Redistat::Finder do
lambda { Redistat::Finder.find(:from => 3.hours.ago) }.should raise_error(Redistat::InvalidOptions) lambda { Redistat::Finder.find(:from => 3.hours.ago) }.should raise_error(Redistat::InvalidOptions)
end end
it "should find children" do describe "Grouping" do
Redistat::Key.new("PageViews", "message/public/die").update_index before(:each) do
Redistat::Key.new("PageViews", "message/public/live").update_index @options = {:scope => "PageViews", :label => "message/public", :from => @two_hours_ago, :till => @one_hour_ago, :depth => :hour, :interval => :hour}
Redistat::Key.new("PageViews", "message/public/fester").update_index @finder = Redistat::Finder.new(@options)
members = db.smembers("#{@scope}#{Redistat::LABEL_INDEX}message/public") # checking 'message/public' end
options = {:scope => "PageViews", :label => "message/public", :from => @two_hours_ago, :till => @one_hour_ago, :depth => :hour, :interval => :hour}
finder = Redistat::Finder.new(options) it "should return parent finder" do
finder.children.first.should be_a(Redistat::Finder) @finder.instance_variable_get("@parent").should be_nil
subs = finder.children.map { |f| f.options[:label].me } @finder.parent.should be_a(Redistat::Finder)
subs.should have(3).items @finder.instance_variable_get("@parent").should_not be_nil
subs.should include('die') @finder.parent.options[:label].to_s.should == 'message'
subs.should include('live') @finder.label('message')
subs.should include('fester') @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 end
describe "Lazy-Loading" do describe "Lazy-Loading" do

View File

@@ -17,12 +17,12 @@ describe Redistat::Label do
it "should store a label hash lookup key" do it "should store a label hash lookup key" do
label = Redistat::Label.new(@name, {:hashed_label => true}).save label = Redistat::Label.new(@name, {:hashed_label => true}).save
label.saved?.should be_true 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" name = "contact_us"
label = Redistat::Label.create(name, {:hashed_label => true}) label = Redistat::Label.create(name, {:hashed_label => true})
label.saved?.should be_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 end
describe "Grouping" do describe "Grouping" do