diff --git a/lib/redistat/finder.rb b/lib/redistat/finder.rb index 08fe381..765e194 100644 --- a/lib/redistat/finder.rb +++ b/lib/redistat/finder.rb @@ -81,49 +81,56 @@ module Redistat } end - def connection_ref(ref) + def connection_ref(ref = nil) + return options[:connection_ref] if ref.nil? reset! if options[:connection_ref] != ref options[:connection_ref] = ref self end - def scope(scope) - reset! if !options[:scope].nil? && options[:scope].to_s != scope - options[:scope] = Scope.new(scope) + def scope(input = nil) + return options[:scope] if input.nil? + reset! if !options[:scope].nil? && options[:scope].to_s != input.to_s + options[:scope] = Scope.new(input) self end - def label(label) - reset! if options.has_key?(:label) && options[:label].to_s != label.to_s - options[:label] = (!label.nil?) ? Label.new(label) : nil + def label(input = nil) + return options[:label] if input.nil? + reset! if options.has_key?(:label) && options[:label].to_s != input.to_s + options[:label] = (!input.nil?) ? Label.new(input) : nil self end - def dates(from, till) - from(from).till(till) + def dates(start, finish) + from(start).till(finish) end alias :date :dates - def from(date) + def from(date = nil) + return options[:from] if date.nil? reset! if options[:from] != date options[:from] = date self end - def till(date) + def till(date = nil) + return options[:till] if date.nil? reset! if options[:till] != date options[:till] = date self end alias :until :till - def depth(unit) + def depth(unit = nil) + return options[:depth] if unit.nil? reset! if options[:depth] != unit options[:depth] = unit self end - def interval(unit) + def interval(unit = nil) + return options[:interval] if unit.nil? reset! if options[:interval] != unit options[:interval] = unit self diff --git a/spec/finder_spec.rb b/spec/finder_spec.rb index 14e9f5c..14fcf33 100644 --- a/spec/finder_spec.rb +++ b/spec/finder_spec.rb @@ -25,31 +25,36 @@ describe Redistat::Finder do finder.options[:label].to_s.should == options[:label] finder.options.should == options.merge(:scope => finder.options[:scope], :label => finder.options[:label]) + finder = Redistat::Finder.scope("hello") + finder.options[:scope].to_s.should == "hello" + finder.scope.to_s.should == "hello" + + finder = Redistat::Finder.label("hello") + finder.options[:label].to_s.should == "hello" + finder.label.to_s.shold == "hello" + finder = Redistat::Finder.dates(@two_hours_ago, @one_hour_ago) finder.options[:from].should == @two_hours_ago finder.options[:till].should == @one_hour_ago - finder = Redistat::Finder.scope("hello") - finder.options[:scope].to_s.should == "hello" - - finder = Redistat::Finder.label("hello") - finder.options[:label].to_s.should == "hello" - finder = Redistat::Finder.from(@two_hours_ago) finder.options[:from].should == @two_hours_ago + finder.from.should == @two_hours_ago finder = Redistat::Finder.till(@one_hour_ago) finder.options[:till].should == @one_hour_ago + finder.till.should == @one_hour_ago finder = Redistat::Finder.depth(:hour) finder.options[:depth].should == :hour + finder.depth.should == :hour finder = Redistat::Finder.interval(true) finder.options[:interval].should be_true - + finder.interval.should be_true finder = Redistat::Finder.interval(false) finder.options[:interval].should be_false - + finder.interval.should be_false end it "should fetch stats properly" do