redistat 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -5,7 +5,6 @@ PATH
5
5
  activesupport (>= 2.3.0)
6
6
  json (>= 1.4.0)
7
7
  redis (>= 2.1.0)
8
- system_timer (>= 1.0.0)
9
8
  time_ext (>= 0.2.8)
10
9
 
11
10
  GEM
@@ -24,7 +23,6 @@ GEM
24
23
  rspec-expectations (2.1.0)
25
24
  diff-lcs (~> 1.1.2)
26
25
  rspec-mocks (2.1.0)
27
- system_timer (1.0)
28
26
  time_ext (0.2.8)
29
27
  activesupport (>= 2.3.0)
30
28
  i18n (>= 0.4.2)
@@ -39,6 +37,5 @@ DEPENDENCIES
39
37
  redis (>= 2.1.0)
40
38
  redistat!
41
39
  rspec (>= 2.1.0)
42
- system_timer (>= 1.0.0)
43
40
  time_ext (>= 0.2.8)
44
41
  yard (>= 0.6.3)
data/README.md CHANGED
@@ -14,6 +14,8 @@ Redis fits perfectly with all of these requirements. It has atomic operations li
14
14
 
15
15
  gem install redistat
16
16
 
17
+ If you are using Ruby 1.8.x, it's recommended you also install the `system_timer` gem, as the Redis gem will otherwise complain.
18
+
17
19
  ## Usage
18
20
 
19
21
  The simplest way to use Redistat is through the model wrapper.
data/lib/redistat.rb CHANGED
@@ -26,6 +26,7 @@ require 'redistat/summary'
26
26
  require 'redistat/core_ext/date'
27
27
  require 'redistat/core_ext/time'
28
28
  require 'redistat/core_ext/fixnum'
29
+ require 'redistat/core_ext/bignum'
29
30
 
30
31
  module Redistat
31
32
 
@@ -54,7 +55,7 @@ module Redistat
54
55
  end
55
56
 
56
57
  def flush
57
- puts "WARNING: Redistat.flush is deprecated. Use Redistat.redis.flush instead."
58
+ puts "WARNING: Redistat.flush is deprecated. Use Redistat.redis.flushdb instead."
58
59
  connection.flushdb
59
60
  end
60
61
 
@@ -0,0 +1,8 @@
1
+ class Bignum
2
+ include Redistat::DateHelper
3
+
4
+ def to_time
5
+ Time.at(self)
6
+ end
7
+
8
+ end
data/lib/redistat/date.rb CHANGED
@@ -22,6 +22,8 @@ module Redistat
22
22
  from_string(input)
23
23
  elsif input.is_a?(::Fixnum)
24
24
  from_integer(input)
25
+ elsif input.is_a?(::Bignum)
26
+ from_integer(input)
25
27
  end
26
28
  end
27
29
 
@@ -42,7 +42,7 @@ module Redistat
42
42
  return find_start_year_for(start_date, end_date, lowest_depth) if unit == :year
43
43
  index = Date::DEPTHS.index(unit)
44
44
  nunit = Date::DEPTHS[(index > 0) ? index-1 : index]
45
- if start_date < start_date.round(nunit) || start_date.next(nunit).beginning_of(nunit) > end_date.beginning_of(nunit)
45
+ if start_date < start_date.beginning_of_closest(nunit) || start_date.next(nunit).beginning_of(nunit) > end_date.beginning_of(nunit)
46
46
  add = []
47
47
  start_date.beginning_of_each(unit, :include_start => lowest_depth).until(start_date.end_of(nunit)) do |t|
48
48
  add << t.to_rs.to_s(unit) if t < end_date.beginning_of(unit)
@@ -59,7 +59,7 @@ module Redistat
59
59
  index = Date::DEPTHS.index(unit)
60
60
  nunit = Date::DEPTHS[(index > 0) ? index-1 : index]
61
61
  has_nunit = end_date.prev(nunit).beginning_of(nunit) >= start_date.beginning_of(nunit)
62
- nearest_nunit = end_date.round(nunit)
62
+ nearest_nunit = end_date.beginning_of_closest(nunit)
63
63
  if end_date >= nearest_nunit && has_nunit
64
64
  add = []
65
65
  end_date.beginning_of(nunit).beginning_of_each(unit, :include_start => true, :include_end => lowest_depth).until(end_date) do |t|
@@ -39,6 +39,15 @@ module Redistat
39
39
  end
40
40
  end
41
41
 
42
+ def class_name(class_name = nil)
43
+ if !class_name.nil?
44
+ options[:class_name] = class_name
45
+ else
46
+ options[:class_name] || nil
47
+ end
48
+ end
49
+ alias :scope :class_name
50
+
42
51
  def depth(depth = nil)
43
52
  if !depth.nil?
44
53
  options[:depth] = depth
@@ -62,7 +71,7 @@ module Redistat
62
71
  private
63
72
 
64
73
  def name
65
- @name ||= self.to_s
74
+ options[:class_name] || (@name ||= self.to_s)
66
75
  end
67
76
 
68
77
  end
@@ -1,3 +1,3 @@
1
1
  module Redistat
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/redistat.gemspec CHANGED
@@ -22,7 +22,6 @@ Gem::Specification.new do |s|
22
22
  s.add_runtime_dependency 'activesupport', '>= 2.3.0'
23
23
  s.add_runtime_dependency 'json', '>= 1.4.0'
24
24
  s.add_runtime_dependency 'redis', '>= 2.1.0'
25
- s.add_runtime_dependency 'system_timer', '>= 1.0.0'
26
25
  s.add_runtime_dependency 'time_ext', '>= 0.2.8'
27
26
 
28
27
  s.add_development_dependency 'rspec', '>= 2.1.0'
data/spec/event_spec.rb CHANGED
@@ -20,7 +20,7 @@ describe Redistat::Event do
20
20
  @event.scope.should == @scope
21
21
  @event.label.should == @label
22
22
  @event.label_hash.should == @label_hash
23
- @event.date.to_time.should == @date
23
+ @event.date.to_time.to_s.should == @date.to_s
24
24
  @event.stats.should == @stats
25
25
  @event.meta.should == @meta
26
26
  @event.options.should == @event.default_options.merge(@options)
@@ -28,10 +28,10 @@ describe Redistat::Event do
28
28
 
29
29
  it "should allow changing attributes" do
30
30
  # date
31
- @event.date.to_time.should == @date
31
+ @event.date.to_time.to_s.should == @date.to_s
32
32
  @date = Time.now
33
33
  @event.date = @date
34
- @event.date.to_time.should == @date
34
+ @event.date.to_time.to_s.should == @date.to_s
35
35
  # label
36
36
  @event.label.should == @label
37
37
  @event.label_hash.should == @label_hash
data/spec/key_spec.rb CHANGED
@@ -46,10 +46,10 @@ describe Redistat::Key do
46
46
  @key.scope = @scope
47
47
  @key.scope.should == @scope
48
48
  # date
49
- @key.date.to_time.should == @date
49
+ @key.date.to_time.to_s.should == @date.to_s
50
50
  @date = Time.now
51
51
  @key.date = @date
52
- @key.date.to_time.should == @date
52
+ @key.date.to_time.to_s.should == @date.to_s
53
53
  # label
54
54
  @key.label.should == @label
55
55
  @key.label_hash == @label_hash
data/spec/model_helper.rb CHANGED
@@ -20,4 +20,11 @@ class ModelHelper3
20
20
 
21
21
  connect_to :port => 8379, :db => 14
22
22
 
23
+ end
24
+
25
+ class ModelHelper4
26
+ include Redistat::Model
27
+
28
+ class_name "FancyHelper"
29
+
23
30
  end
data/spec/model_spec.rb CHANGED
@@ -8,6 +8,7 @@ describe Redistat::Model do
8
8
  ModelHelper1.redis.flushdb
9
9
  ModelHelper2.redis.flushdb
10
10
  ModelHelper3.redis.flushdb
11
+ ModelHelper4.redis.flushdb
11
12
  end
12
13
 
13
14
  it "should should name itself correctly" do
@@ -19,6 +20,7 @@ describe Redistat::Model do
19
20
  ModelHelper2.depth.should == :day
20
21
  ModelHelper2.store_event.should == true
21
22
  ModelHelper2.hashed_label.should == true
23
+ ModelHelper2.class_name.should be_nil
22
24
 
23
25
  ModelHelper1.depth.should == nil
24
26
  ModelHelper1.store_event.should == nil
@@ -35,6 +37,9 @@ describe Redistat::Model do
35
37
  ModelHelper1.depth.should == nil
36
38
  ModelHelper1.store_event.should == nil
37
39
  ModelHelper1.hashed_label.should == nil
40
+
41
+ ModelHelper4.class_name.should == "FancyHelper"
42
+ ModelHelper4.send(:name).should == "FancyHelper"
38
43
  end
39
44
 
40
45
  it "should store and fetch stats" do
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redistat
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 6
10
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
11
10
  platform: ruby
12
11
  authors:
13
12
  - Jim Myhrberg
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-12-01 00:00:00 +00:00
17
+ date: 2010-12-29 00:00:00 +00:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -26,7 +25,6 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- hash: 3
30
28
  segments:
31
29
  - 2
32
30
  - 3
@@ -42,7 +40,6 @@ dependencies:
42
40
  requirements:
43
41
  - - ">="
44
42
  - !ruby/object:Gem::Version
45
- hash: 7
46
43
  segments:
47
44
  - 1
48
45
  - 4
@@ -58,7 +55,6 @@ dependencies:
58
55
  requirements:
59
56
  - - ">="
60
57
  - !ruby/object:Gem::Version
61
- hash: 11
62
58
  segments:
63
59
  - 2
64
60
  - 1
@@ -66,70 +62,51 @@ dependencies:
66
62
  version: 2.1.0
67
63
  type: :runtime
68
64
  version_requirements: *id003
69
- - !ruby/object:Gem::Dependency
70
- name: system_timer
71
- prerelease: false
72
- requirement: &id004 !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- hash: 23
78
- segments:
79
- - 1
80
- - 0
81
- - 0
82
- version: 1.0.0
83
- type: :runtime
84
- version_requirements: *id004
85
65
  - !ruby/object:Gem::Dependency
86
66
  name: time_ext
87
67
  prerelease: false
88
- requirement: &id005 !ruby/object:Gem::Requirement
68
+ requirement: &id004 !ruby/object:Gem::Requirement
89
69
  none: false
90
70
  requirements:
91
71
  - - ">="
92
72
  - !ruby/object:Gem::Version
93
- hash: 7
94
73
  segments:
95
74
  - 0
96
75
  - 2
97
76
  - 8
98
77
  version: 0.2.8
99
78
  type: :runtime
100
- version_requirements: *id005
79
+ version_requirements: *id004
101
80
  - !ruby/object:Gem::Dependency
102
81
  name: rspec
103
82
  prerelease: false
104
- requirement: &id006 !ruby/object:Gem::Requirement
83
+ requirement: &id005 !ruby/object:Gem::Requirement
105
84
  none: false
106
85
  requirements:
107
86
  - - ">="
108
87
  - !ruby/object:Gem::Version
109
- hash: 11
110
88
  segments:
111
89
  - 2
112
90
  - 1
113
91
  - 0
114
92
  version: 2.1.0
115
93
  type: :development
116
- version_requirements: *id006
94
+ version_requirements: *id005
117
95
  - !ruby/object:Gem::Dependency
118
96
  name: yard
119
97
  prerelease: false
120
- requirement: &id007 !ruby/object:Gem::Requirement
98
+ requirement: &id006 !ruby/object:Gem::Requirement
121
99
  none: false
122
100
  requirements:
123
101
  - - ">="
124
102
  - !ruby/object:Gem::Version
125
- hash: 1
126
103
  segments:
127
104
  - 0
128
105
  - 6
129
106
  - 3
130
107
  version: 0.6.3
131
108
  type: :development
132
- version_requirements: *id007
109
+ version_requirements: *id006
133
110
  description: A Redis-backed statistics storage and querying library written in Ruby.
134
111
  email:
135
112
  - contact@jimeh.me
@@ -151,6 +128,7 @@ files:
151
128
  - lib/redistat.rb
152
129
  - lib/redistat/collection.rb
153
130
  - lib/redistat/connection.rb
131
+ - lib/redistat/core_ext/bignum.rb
154
132
  - lib/redistat/core_ext/date.rb
155
133
  - lib/redistat/core_ext/fixnum.rb
156
134
  - lib/redistat/core_ext/time.rb
@@ -198,7 +176,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
198
176
  requirements:
199
177
  - - ">="
200
178
  - !ruby/object:Gem::Version
201
- hash: 3
202
179
  segments:
203
180
  - 0
204
181
  version: "0"
@@ -207,7 +184,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
184
  requirements:
208
185
  - - ">="
209
186
  - !ruby/object:Gem::Version
210
- hash: 3
211
187
  segments:
212
188
  - 0
213
189
  version: "0"