* Redistat::Finder raises an InvalidOptions

exception if options are invalid.
* Separated Finder#find method into smaller parts.
This commit is contained in:
2010-11-07 21:50:39 +00:00
parent 715d96db9c
commit 24bf57000e
4 changed files with 57 additions and 9 deletions

View File

@@ -31,6 +31,8 @@ module Redistat
KEY_EVENT = ".event:"
KEY_LEBELS = "Redistat.lables:"
KEY_EVENT_IDS = ".event_ids"
class InvalidOptions < ArgumentError; end
# Provides access to the Redis database. This is shared accross all models and instances.
def redis

View File

@@ -0,0 +1,7 @@
module Redistat
class Collection < Array
end
end

View File

@@ -15,11 +15,28 @@ module Redistat
def find(options = {})
@options.merge!(options)
return nil if !valid_options?
sets = Finder::DateSet.new(@options[:from], @options[:till], @options[:depth], @options[:interval])
raise InvalidOptions.new if !valid_options?
if @options[:interval].nil? || !@options[:interval]
find_by_magic
else
find_by_interval
end
end
def find_by_interval(options = {})
@options.merge!(options)
raise InvalidOptions.new if !valid_options?
date_sets = Finder::DateSet.new(@options[:from], @options[:till], @options[:depth], @options[:interval])
end
def find_by_magic(options = {})
@options.merge!(options)
raise InvalidOptions.new if !valid_options?
date_sets = Finder::DateSet.new(@options[:from], @options[:till], @options[:depth], @options[:interval])
key = Key.new(@options[:scope], @options[:label])
total_sum = Result.new
sets.each do |set|
date_sets.each do |set|
sum = Result.new
sum = summarize_add_keys(set[:add], key, sum)
sum = summarize_rem_keys(set[:rem], key, sum)