redistat 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -91,7 +91,7 @@ module Redistat
91
91
  event = db.hgetall "#{scope}#{KEY_EVENT}#{id}"
92
92
  return nil if event.size == 0
93
93
  self.new( event["scope"], event["label"], event["date"], JSON.parse(event["stats"]),
94
- JSON.parse(event["meta"]), JSON.parse(event["options"]), false )
94
+ JSON.parse(event["options"]), JSON.parse(event["meta"]), false )
95
95
  end
96
96
 
97
97
  end
@@ -81,49 +81,56 @@ module Redistat
81
81
  }
82
82
  end
83
83
 
84
- def connection_ref(ref)
84
+ def connection_ref(ref = nil)
85
+ return options[:connection_ref] if ref.nil?
85
86
  reset! if options[:connection_ref] != ref
86
87
  options[:connection_ref] = ref
87
88
  self
88
89
  end
89
90
 
90
- def scope(scope)
91
- reset! if !options[:scope].nil? && options[:scope].to_s != scope
92
- options[:scope] = Scope.new(scope)
91
+ def scope(input = nil)
92
+ return options[:scope] if input.nil?
93
+ reset! if !options[:scope].nil? && options[:scope].to_s != input.to_s
94
+ options[:scope] = Scope.new(input)
93
95
  self
94
96
  end
95
97
 
96
- def label(label)
97
- reset! if options.has_key?(:label) && options[:label].to_s != label.to_s
98
- options[:label] = (!label.nil?) ? Label.new(label) : nil
98
+ def label(input = nil)
99
+ return options[:label] if input.nil?
100
+ reset! if options.has_key?(:label) && options[:label].to_s != input.to_s
101
+ options[:label] = (!input.nil?) ? Label.new(input) : nil
99
102
  self
100
103
  end
101
104
 
102
- def dates(from, till)
103
- from(from).till(till)
105
+ def dates(start, finish)
106
+ from(start).till(finish)
104
107
  end
105
108
  alias :date :dates
106
109
 
107
- def from(date)
110
+ def from(date = nil)
111
+ return options[:from] if date.nil?
108
112
  reset! if options[:from] != date
109
113
  options[:from] = date
110
114
  self
111
115
  end
112
116
 
113
- def till(date)
117
+ def till(date = nil)
118
+ return options[:till] if date.nil?
114
119
  reset! if options[:till] != date
115
120
  options[:till] = date
116
121
  self
117
122
  end
118
123
  alias :until :till
119
124
 
120
- def depth(unit)
125
+ def depth(unit = nil)
126
+ return options[:depth] if unit.nil?
121
127
  reset! if options[:depth] != unit
122
128
  options[:depth] = unit
123
129
  self
124
130
  end
125
131
 
126
- def interval(unit)
132
+ def interval(unit = nil)
133
+ return options[:interval] if unit.nil?
127
134
  reset! if options[:interval] != unit
128
135
  options[:interval] = unit
129
136
  self
@@ -9,6 +9,10 @@ module Redistat
9
9
  end
10
10
 
11
11
  def find_date_sets(start_date, end_date, depth = nil, interval = false)
12
+ if depth.nil? && interval.is_a?(Symbol)
13
+ depth = interval
14
+ interval = true
15
+ end
12
16
  start_date = start_date.to_time if start_date.is_a?(::Date)
13
17
  end_date = end_date.to_time if end_date.is_a?(::Date)
14
18
  if !interval
data/lib/redistat/key.rb CHANGED
@@ -30,13 +30,14 @@ module Redistat
30
30
  options[:depth]
31
31
  end
32
32
 
33
- def scope
34
- @scope.to_s
35
- end
33
+ # def scope
34
+ # @scope.to_s
35
+ # end
36
36
 
37
37
  def scope=(input)
38
38
  @scope = (input.instance_of?(Redistat::Scope)) ? input : Scope.new(input)
39
39
  end
40
+ attr_reader :scope
40
41
 
41
42
  def label=(input)
42
43
  @label = (input.instance_of?(Redistat::Label)) ? input : Label.create(input, @options)
@@ -13,7 +13,7 @@ module Redistat
13
13
  #
14
14
 
15
15
  def store(label, stats = {}, date = nil, opts = {}, meta = {})
16
- Event.new(name, label, date, stats, options.merge(opts), meta).save
16
+ Event.new(self.name, label, date, stats, options.merge(opts), meta).save
17
17
  end
18
18
  alias :event :store
19
19
 
@@ -29,6 +29,10 @@ module Redistat
29
29
  :till => till }.merge(options.merge(opts)) )
30
30
  end
31
31
 
32
+ def find_event(event_id)
33
+ Event.find(self.name, event_id)
34
+ end
35
+
32
36
 
33
37
  #
34
38
  # options methods
@@ -1,3 +1,3 @@
1
1
  module Redistat
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
data/spec/event_spec.rb CHANGED
@@ -8,8 +8,8 @@ describe Redistat::Event do
8
8
  @scope = "PageViews"
9
9
  @label = "about_us"
10
10
  @label_hash = Digest::SHA1.hexdigest(@label)
11
- @stats = {:views => 1}
12
- @meta = {:user_id => 239}
11
+ @stats = {'views' => 1}
12
+ @meta = {'user_id' => 239}
13
13
  @options = {:depth => :hour}
14
14
  @date = Time.now
15
15
  @event = Redistat::Event.new(@scope, @label, @date, @stats, @options, @meta)
@@ -17,7 +17,7 @@ describe Redistat::Event do
17
17
 
18
18
  it "should initialize properly" do
19
19
  @event.id.should be_nil
20
- @event.scope.should == @scope
20
+ @event.scope.to_s.should == @scope
21
21
  @event.label.to_s.should == @label
22
22
  @event.label_hash.should == @label_hash
23
23
  @event.date.to_time.to_s.should == @date.to_s
@@ -63,9 +63,11 @@ describe Redistat::Event do
63
63
  it "should find event by id" do
64
64
  @event = Redistat::Event.new(@scope, @label, @date, @stats, @options.merge({:store_event => true}), @meta).save
65
65
  fetched = Redistat::Event.find(@scope, @event.id)
66
- @event.scope.should == fetched.scope
66
+ @event.scope.to_s.should == fetched.scope.to_s
67
67
  @event.label.to_s.should == fetched.label.to_s
68
68
  @event.date.to_s.should == fetched.date.to_s
69
+ @event.stats.should == fetched.stats
70
+ @event.meta.should == fetched.meta
69
71
  end
70
72
 
71
73
  it "should store summarized statistics" do
@@ -28,11 +28,13 @@ describe Redistat::Finder::DateSet do
28
28
  result = Redistat::Finder::DateSet.new.find_date_sets(t_start, t_end, :hour, true)
29
29
  result[0][:add].should == ["2010082818", "2010082819", "2010082820", "2010082821", "2010082822"]
30
30
  result[0][:rem].should == []
31
+ result.should == Redistat::Finder::DateSet.new(t_start, t_end, nil, :hour)
31
32
 
32
33
  t_end = t_start + 4.days
33
34
  result = Redistat::Finder::DateSet.new.find_date_sets(t_start, t_end, :day, true)
34
35
  result[0][:add].should == ["20100828", "20100829", "20100830", "20100831", "20100901"]
35
36
  result[0][:rem].should == []
37
+ result.should == Redistat::Finder::DateSet.new(t_start, t_end, nil, :day)
36
38
  end
37
39
 
38
40
  it "should find start keys properly" do
data/spec/finder_spec.rb CHANGED
@@ -25,31 +25,36 @@ describe Redistat::Finder do
25
25
  finder.options[:label].to_s.should == options[:label]
26
26
  finder.options.should == options.merge(:scope => finder.options[:scope], :label => finder.options[:label])
27
27
 
28
- finder = Redistat::Finder.dates(@two_hours_ago, @one_hour_ago)
29
- finder.options[:from].should == @two_hours_ago
30
- finder.options[:till].should == @one_hour_ago
31
-
32
28
  finder = Redistat::Finder.scope("hello")
33
29
  finder.options[:scope].to_s.should == "hello"
30
+ finder.scope.to_s.should == "hello"
34
31
 
35
32
  finder = Redistat::Finder.label("hello")
36
33
  finder.options[:label].to_s.should == "hello"
34
+ finder.label.to_s.should == "hello"
35
+
36
+ finder = Redistat::Finder.dates(@two_hours_ago, @one_hour_ago)
37
+ finder.options[:from].should == @two_hours_ago
38
+ finder.options[:till].should == @one_hour_ago
37
39
 
38
40
  finder = Redistat::Finder.from(@two_hours_ago)
39
41
  finder.options[:from].should == @two_hours_ago
42
+ finder.from.should == @two_hours_ago
40
43
 
41
44
  finder = Redistat::Finder.till(@one_hour_ago)
42
45
  finder.options[:till].should == @one_hour_ago
46
+ finder.till.should == @one_hour_ago
43
47
 
44
48
  finder = Redistat::Finder.depth(:hour)
45
49
  finder.options[:depth].should == :hour
50
+ finder.depth.should == :hour
46
51
 
47
52
  finder = Redistat::Finder.interval(true)
48
53
  finder.options[:interval].should be_true
49
-
54
+ finder.interval.should be_true
50
55
  finder = Redistat::Finder.interval(false)
51
56
  finder.options[:interval].should be_false
52
-
57
+ finder.interval.should be_false
53
58
  end
54
59
 
55
60
  it "should fetch stats properly" do
data/spec/key_spec.rb CHANGED
@@ -13,7 +13,7 @@ describe Redistat::Key do
13
13
  end
14
14
 
15
15
  it "should initialize properly" do
16
- @key.scope.should == @scope
16
+ @key.scope.to_s.should == @scope
17
17
  @key.label.to_s.should == @label
18
18
  @key.label_hash.should == @label_hash
19
19
  @key.groups.map { |k| k.instance_variable_get("@label") }.should == @key.instance_variable_get("@label").groups
@@ -44,10 +44,10 @@ describe Redistat::Key do
44
44
 
45
45
  it "should allow changing attributes" do
46
46
  # scope
47
- @key.scope.should == @scope
47
+ @key.scope.to_s.should == @scope
48
48
  @scope = "VisitorCount"
49
49
  @key.scope = @scope
50
- @key.scope.should == @scope
50
+ @key.scope.to_s.should == @scope
51
51
  # date
52
52
  @key.date.to_time.to_s.should == @date.to_s
53
53
  @date = Time.now
data/spec/model_spec.rb CHANGED
@@ -28,6 +28,11 @@ describe Redistat::Model do
28
28
  finder.options[:till].should == one_hour_ago
29
29
  end
30
30
 
31
+ it "should #find_event" do
32
+ Redistat::Event.should_receive(:find).with('ModelHelper1', 1)
33
+ ModelHelper1.find_event(1)
34
+ end
35
+
31
36
  it "should listen to model-defined options" do
32
37
  ModelHelper2.depth.should == :day
33
38
  ModelHelper2.store_event.should == true
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redistat
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jim Myhrberg
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-03-12 00:00:00 +00:00
18
+ date: 2011-03-13 00:00:00 +00:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency