diff --git a/lib/redistat/event.rb b/lib/redistat/event.rb index 620be37..b447d20 100644 --- a/lib/redistat/event.rb +++ b/lib/redistat/event.rb @@ -1,21 +1,26 @@ module Redistat class Event - attr_reader :scope attr_reader :key - attr_accessor :data + attr_accessor :stats + attr_accessor :meta attr_accessor :options - def initialize(scope, label = nil, data = {}, date = nil, options = {}) - @options = options + def initialize(scope, label = nil, date = nil, stats = {}, meta = {}, options = {}) + @options = default_options.merge(options) @scope = scope - @key = Key.new(scope, label, date, options) - #TODO ...intialize Redistat::Event + @key = Key.new(scope, label, date, @options) + @stats = stats ||= {} + @meta = meta ||= {} + end + + def default_options + { :depth => :hour, } end def date - @key.date.to_time + @key.date end def date=(input) @@ -25,6 +30,14 @@ module Redistat alias :time :date alias :time= :date= + def scope + @key.scope + end + + def scope=(input) + @key.scope = input + end + def label @key.label end diff --git a/lib/redistat/key.rb b/lib/redistat/key.rb index 3d741c1..c4bc4dd 100644 --- a/lib/redistat/key.rb +++ b/lib/redistat/key.rb @@ -3,12 +3,13 @@ module Redistat attr_accessor :scope attr_accessor :date + attr_accessor :options def initialize(scope, label = nil, date = nil, options = {}) @scope = scope self.label = label if !label.nil? self.date = date ||= Time.now - @options = options + self.options = options end def date=(input) diff --git a/spec/event_spec.rb b/spec/event_spec.rb index 7ec7370..9d838a1 100644 --- a/spec/event_spec.rb +++ b/spec/event_spec.rb @@ -6,29 +6,27 @@ describe Redistat::Event do @scope = "PageViews" @label = "about_us" @label_hash = Digest::SHA1.hexdigest(@label) + @stats = {:views => 1} + @meta = {:user_id => 239} + @options = {:depth => :hour} @date = Time.now - @event = Redistat::Event.new(@scope, @label, {:views => 1}, @date, {:depth => :hour}) + @event = Redistat::Event.new(@scope, @label, @date, @stats, @meta, @options) end # it "should initialize properly" - it "should allow changing Date" do - @event.time.should == @date - + it "should allow changing attributes" do + # date + @event.date.to_time.should == @date @date = Time.now @event.date = @date - - @event.time.should == @date - end - - it "should allow changing Label" do + @event.date.to_time.should == @date + # label @event.label.should == @label @event.label_hash.should == @label_hash - @label = "contact_us" @label_hash = Digest::SHA1.hexdigest(@label) @event.label = @label - @event.label.should == @label @event.label_hash.should == @label_hash end diff --git a/spec/key_spec.rb b/spec/key_spec.rb index 8f51c85..663d953 100644 --- a/spec/key_spec.rb +++ b/spec/key_spec.rb @@ -30,19 +30,22 @@ describe Redistat::Key do it "should abide to hash_label option" do @key = Redistat::Key.new(@scope, @label, @date, {:depth => :day, :label_hash => true}) @key.to_s.should == "#{@scope}/#{@label_hash}:#{@key.date.to_s(:day)}" - @key = Redistat::Key.new(@scope, @label, @date, {:depth => :day, :label_hash => false}) @key.to_s.should == "#{@scope}/#{@label}:#{@key.date.to_s(:day)}" end - it "should allow changing Date" do + it "should allow changing attributes" do + # scope + @key.scope.should == @scope + @scope = "VisitorCount" + @key.scope = @scope + @key.scope.should == @scope + # date @key.date.to_time.should == @date - now = Time.now - @key.date = now - @key.date.to_time.should == now - end - - it "should allow changing Label" do + @date = Time.now + @key.date = @date + @key.date.to_time.should == @date + # label @key.label.should == @label @key.label_hash == @label_hash @label = "contact_us"